Wednesday, February 11, 2009

StringCollection vs ArrayList

ArrayList is Obsolete.

ArrayList of strings, better or StringCollection .

Cost of Casting occurs in both cases when accessing item from both collections.

ArrayList we need to implement toString(), StringCollection Wrapper implements this method internally.

Friday, February 6, 2009

Client-side Paging for DataGrids

Example to use js array to bind a GridView

Using Ajax Data Controls we can do this.

here is the sample

"<" AjaxData:Gridview ID="ImagesList" runat="server" Visible=True ">"



function pageLoad(sender, e)
var data = new Array();
data[0] = { Id: 1, Name: "Scott" };
data[1] = { Id: 2, Name: "Tiger" };
data[2] = { Id: 3, Name: "Zeke" };
data[3] = { Id: 3, Name: "Joe" };

Wednesday, February 4, 2009

AJAX GridView paging Cutting Edge

C# Code copy and paste....

protected void bindGridView()
string connectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ToString();
SqlConnection sqlCon = new SqlConnection(connectionString);

SqlCommand sqlCmd = new SqlCommand("select * from products", sqlCon);
sqlCmd.CommandType = CommandType.Text;
SqlDataAdapter sqlAdp = new SqlDataAdapter(sqlCmd);
DataSet myDataSet = new DataSet();

// Delay the current Thread to display
// the UpdateProgress status
// Not required in real projects

GridView1.DataSource = myDataSet;
catch (Exception ex)
lblErrorMsg.Text = ex.Message;

protected void btnLoadData_Click(object sender, EventArgs e)

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
GridView1.PageIndex = e.NewPageIndex;

Note: i was trying to execute this using PageIndex Changed . instead use PageIndexChanging.. paging works fine.

ajax for beginners

I dont know why some one has named it ajax. but in 2003 i have written an application using xmlhttp object . which was used to communicate with xml webservice to get a resultset. and display the results in excel.

i will show the example what i have done in my next post.

motivation is share mere yaar " share the knowledge" .

ajax is asynchronous call made using javascript either to the .net web application or webservice.

we need following minumum javascript methods to make a call.

/*---- Get xml http object ---*/

function GetXmlHttpObject() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;


function stateChanged() {
if (xmlHttp.readyState == 4) {
....Write your code to assign response to the html dom element.

here is the java script funtino can be called on each key up on text box
following function gets the employee details from getEmployee.aspx page.

function showEmployee(str) {
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
alert("Your browser does not support AJAX!");
var url = "getEmployee.aspx";
url = url + "?q=" + str;
url = url + "&sid=" + Math.random();
xmlHttp.onreadystatechange = stateChanged;"GET", url, true);

any questions please drop a question.