Stephen Forte's Weblog
A complete waste of time…

 



Subscribe to "Stephen Forte's Weblog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 

 

  Friday, June 27, 2003


DataGrid Nirvana

 

Last night us RDs went to a traditional North African sheesha (looks like a fancy bong) bar to smoke fancy tobacco. We even got Andrew Brust to smoke out of it (apple flavored tobacco)! All done with my sessions, so Goksin and I will go visit historic Carthage.

 

North African developers love the ASP .NET DataGrid. My session, Asp .Net DataGrid Drill Down (Code and Slide Download) was so much fun and fun was had by all. The sorting code went over very well. here is the code we spent the most time on:

private void SortGrid(object source,DataGridSortCommandEventArgs e)

{

//SQL String that will be used

string strSQL = "Select * From Customers";

//the Order By

string strOrderBy = "ASC";

 

//See what the viewstate has for the sortfield and ASC/DESC

if (e.SortExpression.ToString() == ViewState["sortField"].ToString())

{

//a match, see if ASC or DESC

strOrderBy = ViewState["sortDirection"].ToString();

//now toggle the viewstate for later

switch (strOrderBy)

{

case "ASC":

ViewState["sortDirection"] = "DESC";

break;

case "DESC":

ViewState["sortDirection"] = "ASC";

break;

}

}

else

{

//New Field, so it will be ASC by default, so make DESC

ViewState["sortField"] = e.SortExpression.ToString();

ViewState["sortDirection"] = "DESC";

}

//SQL statement compelted

strSQL = strSQL + " " + " ORDER BY [" + e.SortExpression + "] " + strOrderBy;

//set the grid to the first page before you resort

DataGrid1.CurrentPageIndex = 0;

//call the FillGrid method to rebind the grid w/ new OrderBy

FillGrid(strSQL);

}


8:17:20 AM    


Click here to visit the Radio UserLand website. © Copyright 2003 Stephen Forte.
Last update: 7/30/2003; 1:40:37 PM.

June 2003
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
May   Jul