Reputation: 585
I have a gridview it includes checkboxes. When i click them it goes to SelectedRss_Click function and I can keep the data thanks to it. However, when i change tha page of gridview, the checked checkboxes are unchecked. How can i solve this problem.
My SelectedRss_Click function.
protected void SelectedRss_Click(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
ArrayList listcategory = new ArrayList();
list.Clear();
listcategory.Clear();
foreach (GridViewRow row in GridView1.Rows)
{
// Access the CheckBox
CheckBox cb = (CheckBox)row.FindControl("FeedSelector");
if (cb != null && cb.Checked)
{
string feedURL = ((HiddenField)GridView1.Rows[row.RowIndex].FindControl("HiddenField1")).Value;
string rsscategory = GridView1.Rows[row.RowIndex].Cells[2].Text.ToString();
list.Add(feedURL);
listcategory.Add(rsscategory);
Session["SelectedFeedURL"] = list;
Session["SelectedFeedCategory"] = listcategory;
}
}
}
Upvotes: 1
Views: 1829
Reputation: 10095
It's because by end of the Page Life Cycle all controls get Disposed
and State of the Page
will be lost.
Preventive Action
While changing the page of GridView
, in the PageindexChanging
event of GridView
,
save checked checkboxes row details of the Current Page in ViewState
. Similarly you
can remove the rows from ViewState
from unchecked GridView CheckBox
rows.
Corrective Action
The saved records in ViewState
will be checked in GridView on PageIndexChanging
Event.
Upvotes: 1