当单击更新按钮时,按钮的文本将在服务器中更改...我该怎么办 [英] when click on update button then the text of the button will be changed in server...what i do

查看:90
本文介绍了当单击更新按钮时,按钮的文本将在服务器中更改...我该怎么办的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在网格视图中单击更新按钮,那么我希望单击按钮的文本将被更改,但其他按钮具有相同的contaxt.文本也将在后端服务器中更改.
请告诉我如何使用for循环.给我发代码.

我的代码是

If i click on the update button in grid view then I want that the text of the click button will be change but other button have same contaxt. The text will also changed in backend server.
Please tell me how can I use for loop. Send me code.

My code is

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    int index = GridView1.EditIndex;
    GridViewRow row = GridView1.Rows[index];
    TextBox t1 = row.FindControl("txtemp_name") as TextBox;
    TextBox t2 = row.FindControl("txtemp_add") as TextBox;
    TextBox t3 = row.FindControl("txtemp_mob") as TextBox;
    TextBox t4 = row.FindControl("txtsalary") as TextBox;
    string t5= GridView1.DataKeys[e.RowIndex].Value.ToString();
    string dt = "update employee set emp_name='" + t1.Text + "',emp_add='" + t2.Text + "',emp_mob='" + t3.Text+ "',salary='" + t4.Text+ "'where emp_id=" + t5+ "";
    con.Open();
    cmd = new SqlCommand(dt, con);
    cmd.ExecuteNonQuery();
    GridView1.EditIndex = -1;
    con.Close();
    bind();
}

推荐答案

在gridviewButton中设置CommandName(源代码)........
设置后
受保护的无效grvName_RowCommand(对象发送者,GridViewCommandEventArgs e)
{
如果(e.CommandName =="grvModify")
{
TextBox txt1 =(TextBox)grvPO.FindControl("txtname");

您的代码(输入karyo te类型)
int index = GridView1.EditIndex;
GridViewRow行= GridView1.Rows [index];
TextBox t1 = row.FindControl("txtemp_name")as TextBox;
TextBox t2 = row.FindControl("txtemp_add")as TextBox;
TextBox t3 = row.FindControl("txtemp_mob")as TextBox;
TextBox t4 = row.FindControl("txtsalary")as TextBox;
字符串t5 = GridView1.DataKeys [e.RowIndex] .Value.ToString();
字符串dt =更新员工集emp_name =""+ t1.Text +"'',emp_add =" + t2.Text +'',emp_mob =""+ t3.Text +"'',salary = ""+ t4.Text +"''其中emp_id ="+ t5 +";
con.Open();
cmd =新的SqlCommand(dt,con);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
con.Close();
bind();
}
}
Set CommandName in gridviewButton(Source Code) ........
after set
protected void grvName_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "grvModify")
{
TextBox txt1 = (TextBox)grvPO.FindControl("txtname");
or
your code(je te type karyo te)
int index = GridView1.EditIndex;
GridViewRow row = GridView1.Rows[index];
TextBox t1 = row.FindControl("txtemp_name") as TextBox;
TextBox t2 = row.FindControl("txtemp_add") as TextBox;
TextBox t3 = row.FindControl("txtemp_mob") as TextBox;
TextBox t4 = row.FindControl("txtsalary") as TextBox;
string t5= GridView1.DataKeys[e.RowIndex].Value.ToString();
string dt = "update employee set emp_name=''" + t1.Text + "'',emp_add=''" + t2.Text + "'',emp_mob=''" + t3.Text+ "'',salary=''" + t4.Text+ "''where emp_id=" + t5+ "";
con.Open();
cmd = new SqlCommand(dt, con);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
con.Close();
bind();
}
}


这篇关于当单击更新按钮时,按钮的文本将在服务器中更改...我该怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆