Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 30-Jan-13 20:00pm
Edited 31-Jan-13 2:03am
v4
Comments
AdityaPratapSingh at 31-Jan-13 2:09am
   
what do u want ? write your question here in meaningful sense.
_Amy at 31-Jan-13 2:11am
   
Your question is completely Incomplete/Unclear. Please improve your question so that we can understand the error.
sjelen at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
 
protected void Page_Load(object sender, EventArgs e)
{
 
if (!IsPostBack)
{
//First time page load
}
else
{
// subsequent page load
}
 
Hope that helps
Milind
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hello mbsaravanan575,
 
Put your Content inside Update Panel
 
It May Help You.
 

Thanks
  Permalink  
v2

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 367
1 Abhinav S 226
2 thatraja 220
3 OriginalGriff 195
4 Peter Leow 160
0 Sergey Alexandrovich Kryukov 8,849
1 OriginalGriff 5,035
2 Peter Leow 3,949
3 Maciej Los 3,535
4 Abhinav S 3,148


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid