Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void Button3_Click(object sender, EventArgs e)
{
   bool isAnythingChecked = false;
 
   foreach (GridViewRow row in GridView1.Rows)
   {
      CheckBox chk = (CheckBox)row.FindControl("chk1");
      string empname = row.Cells[1].Text;
      string leaveid = row.Cells[2].Text;
      if (chk != null && chk.Checked)
      {
         isAnythingChecked = true;
          try
          {
              //Create sql connection and command
              string strConnect;
              strConnect = "Data Source=BALA;Initial Catalog=employees;Persist Security Info=True;User ID=sa;Password=mips123";
              SqlConnection Connection = new SqlConnection(strConnect);
              string strUpdate = "Update Leave set status = 'Approved' WHERE (LeaveID =" + leaveid + ") AND (EmpID = (Select EmpID from Emp where (Empname='" + empname + "')))";
              SqlCommand command = new SqlCommand(strUpdate, Connection);
              Connection.Open();
              command.ExecuteNonQuery();
              Connection.Close();
              Getuser1();

          }
          catch (Exception exc)
          {

          }

      }
   }
    
   if (!isAnythingChecked)
   {
      Label2.Text = "Please select atlease one record";
   }

Note:-
       how to avoid page postback on button click ,please help me friends
Posted
Updated 31-Jan-13 2:03am
v4
Comments
AdityaPratapSingh 31-Jan-13 2:09am    
what do u want ? write your question here in meaningful sense.
_Amy 31-Jan-13 2:11am    
Your question is completely Incomplete/Unclear. Please improve your question so that we can understand the error.
sjelen 31-Jan-13 7:09am    
What else part are you talking about - you didn't show that code? Page is supposed to postback on button click, that's how ASP webforms work.
Explain what you are trying to achieve.

Well, what is the question.
Page will definitely post back on button click (or any such event or server side control). You need to handle your code in Page_Load using isPostBack

C#
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
//First time page load
}
else
{
// subsequent page load
}


Hope that helps
Milind
 
Share this answer
 
Hello mbsaravanan575,

Put your Content inside Update Panel

It May Help You.


Thanks
 
Share this answer
 
v2

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