C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

hi deepika haridasa


Posted Date: 24 Nov 2008      Posted By: ravi      Member Level: Gold     Points: 1   Responses: 5




hi,

for this program


private void RememberOldValues()
{
ArrayList IDList = 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)
IDList = (ArrayList)Session[CHECKED_ITEMS];
if (result)
{
if (!IDList.Contains(index))
IDList.Add(index);
}
else
IDList.Remove(index);
}
if (IDList != null && IDList.Count > 0)
Session[CHECKED_ITEMS] = IDList;
}


where u r assigning value to Session[CHECKED_ITEMS]. means in which event and how u r taking. plz post in detail. urgent.






Responses

Author: Deepika Haridas    24 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     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 2008Member Level: DiamondRating: 2 out of 52 out of 5     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 2008Member Level: GoldRating: 2 out of 52 out of 5     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 2008Member Level: DiamondRating: 2 out of 52 out of 5     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 2008Member Level: GoldRating: 2 out of 52 out of 5     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



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : pie chart
Previous : check box list selection
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use