public const string SELECTED_CUSTOMERS_INDEX = "SelectedCustomersIndex";
private void RePopulateCheckBoxes()
{
foreach (GridViewRow row in grdInvitee.Rows)
{
var chkBox = row.FindControl("CheckBox1") as CheckBox;
IDataItemContainer container = (IDataItemContainer)chkBox.NamingContainer;
if (SelectedCustomersIndex != null)
{
if (SelectedCustomersIndex.Exists(i => i == container.DataItemIndex))
{
chkBox.Checked = true;
}
}
}
}
private List
{
get
{
if (ViewState[SELECTED_CUSTOMERS_INDEX] == null)
{
ViewState[SELECTED_CUSTOMERS_INDEX] = new List
}
return (List
}
}
private void RemoveRowIndex(int index)
{
SelectedCustomersIndex.Remove(index);
}
private void PersistRowIndex(int index)
{
if (!SelectedCustomersIndex.Exists(i => i == index))
{
SelectedCustomersIndex.Add(index);
}
}
WRITE THIS IN GRIDVIEW PAGEINDEXCHANGING
protected void grdInvitee_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
foreach (GridViewRow row in grdInvitee.Rows)
{
var chkBox = row.FindControl("CheckBox1") as CheckBox;
IDataItemContainer container = (IDataItemContainer)chkBox.NamingContainer;
if (chkBox.Checked)
{
PersistRowIndex(container.DataItemIndex);
}
else
{
RemoveRowIndex(container.DataItemIndex);
}
}
grdInvitee.PageIndex = e.NewPageIndex;
PopulateInviteeGrid();
RePopulateCheckBoxes();
}
No comments:
Post a Comment