1.在模板列中放一button和textobx,textbox用来存放产品名,将button的commandname设置为deletee 并且在html中将他的CommandArgument属性和RowIndex进行绑定: <asp:TemplateField HeaderText="产品名"> 后台中输出模板列中textbox中的值(保存的产品的id): protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) // int i = ((GridViewRow)((Button)e.CommandSource).NamingContainer).RowIndex;//(该方法不需要html中的绑定,取id.刚刚看到的,加上来,好方法.......)
} }
注解: int rowIndex = ((GridViewRow)((Button)e.CommandSource).NamingContainer).RowIndex;
原理是:将当前行索引和Button的commandargument绑定,用的时候只要取出当前行的索引即可...... gridview的rowcommand事件和datalist的itemcommand事件相似.......... |
转载于:https://www.cnblogs.com/verygood1127/archive/2012/05/03/2480333.html