| Author: Deepika Haridas 24 Nov 2008 | Member Level: Diamond | Rating:  Points: 5 |
this is the whole code
on your .aspx page
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" PageSize="5" Width="324px" DataKeyNames="CategoryID" OnPageIndexChanging="GridView1_PageIndexChanging"> <Columns> <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" /> <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" /> <asp:TemplateField HeaderText="Select"> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Thanks & Regards, Deepika Editor
If U want to shine like a SUN..First U have to burn like the SUN!! Need a Guide? Join my mentor program..
|
| Author: Deepika Haridas 24 Nov 2008 | Member Level: Diamond | Rating:  Points: 6 |
code behind page code
private void BindData() { SqlConnection myConnection = new SqlConnection(ConnectionString); SqlDataAdapter ad = new SqlDataAdapter(QUERY_SELECT_ALL_CATEGORIES, myConnection); DataSet ds = new DataSet(); ad.Fill(ds, "Categories"); GridView1.DataSource = ds; GridView1.DataBind(); }
private void RememberOldValues() { ArrayList categoryIDList = new ArrayList(); int index = -1; foreach (GridViewRow row in GridView1.Rows) { index = (int) GridView1.DataKeys[row.RowIndex].Value; bool result = ((CheckBox)row.FindControl("CheckBox1")).Checked; // Check in the Session if (Session[CHECKED_ITEMS] != null) categoryIDList = (ArrayList)Session[CHECKED_ITEMS]; if (result) { if (!categoryIDList.Contains(index)) categoryIDList.Add(index); } else categoryIDList.Remove(index); } if (categoryIDList != null && categoryIDList.Count > 0) Session[CHECKED_ITEMS] = categoryIDList; }
private void RePopulateValues() { ArrayList categoryIDList = (ArrayList)Session[CHECKED_ITEMS]; if (categoryIDList != null && categoryIDList.Count > 0) { foreach (GridViewRow row in GridView1.Rows) { int index = (int)GridView1.DataKeys[row.RowIndex].Value; if (categoryIDList.Contains(index)) { CheckBox myCheckBox = (CheckBox) row.FindControl("CheckBox1"); myCheckBox.Checked = true; } } } }
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { RememberOldValues(); GridView1.PageIndex = e.NewPageIndex; BindData(); RePopulateValues(); }
Thanks & Regards, Deepika Editor
If U want to shine like a SUN..First U have to burn like the SUN!! Need a Guide? Join my mentor program..
|
| Author: ravi 24 Nov 2008 | Member Level: Gold | Rating:  Points: 3 |
Hi deepika
Im using .Net 2003 .In that for datagrid "pageindexchanging" event is not there. i have to handle this with "pageindexchanged" event".
|
| Author: Deepika Haridas 24 Nov 2008 | Member Level: Diamond | Rating:  Points: 0 |
try out that if its working
Thanks & Regards, Deepika Editor
If U want to shine like a SUN..First U have to burn like the SUN!! Need a Guide? Join my mentor program..
|
| Author: ravi 24 Nov 2008 | Member Level: Gold | Rating:  Points: 4 |
hi,
I tried ur code but it is not working. output is like this.
if am selecting 1,2,3 checkboxes in 1st page then 4,5 checkboxes in 2nd page then 6th checkbox on 3rd page and again if i will click on 2nd page it is showing 6th checkbox as checked. i.e it is taking lastpage's value for all pages.plz suggest a solution.
regards ravi
|