给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]

抓几张图贴出,看看估计就明白了。
(1)在GridView中加入模版列,在模版列中放入按钮。(这个前面已介绍过)
给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]

(2)单击GridView编辑模版。
给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]

(3)进入如下界面:
给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]

(4)单击按钮,点击下面图中的“编辑DataBinding”项,进入(5):
给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]

(5)进入按钮的DataBinding界面后,把可绑定属性下的“CommandArgument”项的字段绑定为需要的字段,单击确定按钮后,设置就完成了。
给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]

(6)按钮属性值绑定完毕后,即可在按钮的事件中引用该按钮的CommandArgument绑定值了。

(7)引用方式:例子如下:

  这是GridView列表模版列中删除按钮触发的事件,有用到调用按钮绑定值:

1给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]protected void Button6_Click(object sender, EventArgs e)
2给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]    给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]{
3给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]        SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["BaseConnectionString"].ConnectionString);
4给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]        myconn.Open();
5给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]        string sql = "delete Biaozhun_MX where BiaozhunMXID= "+((Button)sender).CommandArgument.ToString();
6给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]        SqlCommand mycommand = new SqlCommand(sql, myconn);
7给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]        mycommand.ExecuteNonQuery();
8给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]        GridView1.DataBind();
9给GridView模版列中的按钮的CommandArgument属性绑定值及调用 [转]    }


总结:调用绑定值的语句:((Button)sender).CommandArgument.ToString()

 

 

------------------------------------------------------------------------------------

转自http://www.cnblogs.com/zrlhappy/articles/749299.html

------------------------------------------------------------------------------------

转载于:https://www.cnblogs.com/UouHt/archive/2008/12/08/1350634.html