本文介绍了页面按钮点击后回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
推荐答案
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//First time page load
}
else
{
// subsequent page load
}
希望有所帮助
Milind
Hope that helps
Milind
这篇关于页面按钮点击后回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!