# Monday, June 2, 2003

Dallas, Texas. (Speaking at Tech*ED)

Recovering from the Regional Director party last night. Did way too much karaoke with Steve Lasker, Jon Box and Scott Stanfield. We had some good fun. I did decide that Scott Hanselman is not as cool as I thought, he backed out on some of my pranks. Clemens Vasters on the other hand is lots of fun and will party hard at Tech*ED in Europe and Asia as well as Africa.

Day 1 of TechED was good so far. Started with a morning run and then attended Adam Cogan's session on SQL Server and hung out and caught up in the speakers lounge. Proctered the SQL CE lab and then head off to a dinner with MSFT SR. VP Paul Flessner. I speak on Wedneday and Thursday, so I need to get my demos up and running!

I rewrote some examples. Here is some code to toggle the color of a cell in a DataGrid based on the data presented:

public void ToggleYellow(object sender, DataGridItemEventArgs e)

{

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

{

//get the data that is in the current record

if (e.Item.Cells[2].Text == "Sales Representative")

{

//make the cell yellow

e.Item.Cells[2].BackColor = System.Drawing.Color.Yellow;

}}}

 

Here is a custom sorting routine:

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);

}

posted on Monday, June 2, 2003 5:40:45 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [11] Trackback