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["SortExpression"]))
{
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
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["SortExpression"]))
{
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