There are several ASP.NET server controls that make use of view state that enables you to preserve settings that are made during communications with different elements on the page. Data grid is one of the most popular server controls.

Follow the codes below to use View State:

private void AttachImageToHeader(string strHeader, string SortType)       
{
string[] strHeaderViewState=(string[])ViewState["HeaderText"];
string strTempHeader;
int i=0; /// For header string array in view state (index)
foreach(System.Web.UI.WebControls.DataGridColumn d in grdServiceCharge.Columns)
{
d.HeaderText=strHeaderViewState[i]; //reset the headers of the grid to original text
if(d.SortExpression == strHeader)
{
strTempHeader= strHeaderViewState[i];
if (SortType=="Asc")
{
d.HeaderText= strTempHeader +"<IMG height='10' src='../images/arrow_up.gif' width='10' align='absMiddle' border='0'>";
}
else
{
d.HeaderText=strTempHeader + "<IMG height='10' src='../images/arrow_down.gif' width='10' align='absMiddle' border='0'>";
}               
}
i++;
} // foreach loop
}// AttachImageToHeader function
                    

Copyright © 2008 VisualBuilder. All rights reserved