Postback does maintain datagrid sort direction image ?

R

rockdale

Hi, All:
I dynamic add an arrow up/down image in OnItemDataBound event for my
datagrid, it works fine. But I have another textbox which trigger
postback and doing something, after this event get executed, I lost the

image but the datagrid maintain the same sort order. Should the
datagrid remain what it looks like (with the riget arrow up/down image)

before the postback caused by the textbox?

I tried to get the datagrid header in the text postback event
(OnChanged), but I do not know how to get the datagrid header. I do not

want to rebind the datagrid in the textbox OnChanged event.


Or should I use other method to show the sort direction image?


private void dgrid_OnItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//Sorting Image
if(e.Item.ItemType == ListItemType.Header)
{
foreach(TableCell tc in e.Item.Cells)
{
if(tc.Controls.Count > 0)
{
try
{
LinkButton lkbSortCol =
(System.Web.UI.WebControls.LinkButton)tc.Controls[0];

if(lkbSortCol.CommandArgument.ToString().Equals(dgrid.Attributes["SortExpre­ssion"]))

{

System.Web.UI.WebControls.Image imgSort = new
System.Web.UI.WebControls.Image();

if(dgrid.Attributes["SortDirection"].Equals("DESC"))
{

imgSort.ImageUrl = Server.MapPath("Images/sort_desc.gif");
}
else
{

imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
}


tc.Controls.AddAt(1,
imgSort);
}
}
catch(Exception ex)
{
Trace.Write(ex.Message);
}
}//end if tc.controls.count > 0
}//end for


} //end item type


Thanks a lot
-Rockdale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top