Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a gridview in that I have taken a checkbox to select all the item and a button outside gridview to change the status of all items in gridview .Every things is working fine for me on click event of button status are changed but after the data still shows in grid view I am posting my code if any one can help me .I will be very thankful to u.


C#
protected void Button1_Click(object sender, EventArgs e)
   {
       foreach (GridViewRow row in GVTimeDedction.Rows)
       {
           CheckBox CheckBox1 = (CheckBox)row.FindControl("chkSelect");
           //Checking for the checkbox is checked or not
           if (CheckBox1.Checked == true)
           {
               ID = GVTimeDedction.DataKeys[row.RowIndex].Value.ToString();
               int ReasonId = Convert.ToInt32(ID.ToString());
               reaseon.ChangeStatusOfTime(ReasonId);
              
           }
       }
       BindGridTimeDeduction();
   }



on page load event i have called post back like hthis

C#
if (!IsPostBack)
        {
            BindGridTimeDeduction();
            
        }


I have used an updatting Panel of Ajax.
But I don't there should be a problem.
Posted
Updated 2-Jan-11 19:31pm
v2
Comments
Sandeep Mewara 3-Jan-11 2:09am    
Your issue is not clear. What do you mean by "but after the data still shows in grid view "?
What exactly you want to achieve?
TejuKrishna 3-Jan-11 2:21am    
Your Changes Are made to database after executing this code.
Ankur\m/ 3-Jan-11 2:40am    
The code seems fine. There must be some problem in your method - ChangeStatusOfTime(ReasonId).
Have you checked the values in the database. Are they getting updated?

1 solution

From the provided code fragments my guess is that calling BindGridTimeDeduction after the foreach loop reloads/resets the data.

This seems to support that conclusion:
C#
if (!IsPostBack)
{
  BindGridTimeDeduction();
}


If I'm wrong you have to provide a more detailed description (and code) to get a sensible answer

Regards
Espen Harlinn
 
Share this answer
 
Comments
Mohd Wasif 4-Jan-11 2:15am    
Every thing is working fine and the values are updating in database but the things is even there are no records in database in it is showing in Gridview.
After foreach loop i did it
if (!IsPostBack)
{
BindGridTimeDeduction();
}
but no solutions I got.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900