button控件的CommandArgument属性值应该设置为什么?
{
foreach (GridViewRow row in this.GridView1.Rows)
{
if (this.GridView1.DataKeys[row.RowIndex].Value.ToString() == e.CommandArgument.ToString())
{
TextBox txt = (TextBox)row.FindControl("txtType");
string strConn = ConfigurationManager.ConnectionStrings["DB_website"].ConnectionString;
SqlDataSource ds = new SqlDataSource();
ds.ConnectionString = strConn;
ds.InsertCommand = string.Format("insert into tb_websitetype values({0},'{1}')", 1, txt.Text);
if (ds.Insert() > 0)
{
wmb.MessageBox("添加类型成功~");
DropDownList ddl = (DropDownList)row.FindControl("ddl");
ddl.DataBind();
}
}
}
}
在这段代码中,e.CommandArgument的值会是什么? 那么button属性的CommandArgument值应该设置为什么?
相关推荐
asp.net button 绑定多个参数
代码如下:CommandName=”id_” CommandArgument='<%#Eval(“id_comments_”)+”,”+Eval(“iscertification_comments_”) %>’ OnCommand=”comment_click” 代码如下:protected void comment_click(object sender,CommandEventArgs e) { string temp = e.CommandArgument.ToString(); MessageBox.Show(temp); } 您可能感
响应 GridView 控件中的按钮事件
在单击 GridView 控件中的按钮时,将引发 RowCommand 事件。 GridView 控件具有内置功能,用于进行编辑、删除和分页等操作。 还可以添加按钮并使用 RowCommand 事件向控件添加自定义功能。 可以通过下面的方式向 GridView 控件添加自定义功能: 向 GridView 控件添加 ButtonField 字段。 向 GridView 控件中的模板添加 Button、LinkButton 或 ImageButton 控件。 可以使用事件参数的 CommandName 属性在事件处理程序方法中标识按钮的功能。 如果使用的是 ButtonField 或 TemplateField 对象,则还可以使用 CommandArgument 属性来标识当前行。 使用的是 ButtonField 对象时,CommandArgument 属性自动设置为行索引。 使用的是 TemplateField 对象时,控件不会自动设置 CommandArgument 属性。 在这种情况下,如果必须在事件处理程序中确定行索引,则可以使用数据绑定表达式将该按钮的 CommandArgument 属性设置为行索引。 响应 GridView 控件中的按钮事件 将按钮的 CommandName 属性设置为标识其功能的字符串,如“打印”或“复制”。 如果使用的是 TemplateField 对象并且必须在事件处理程序方法中访问行索引,则将按钮的 CommandArgument 属性设置为标识当前行的表达式。 下面的示例演示如何将 TemplateField 列中某个按钮的 CommandArgument 属性设置为当前行索引。 在该示例中,该列包含一个显示购物车的 Button 控件。 VBC#C++F#JScript 复制不支持该语言或没有可用的代码示例。 VBC#C++F#JScript 复制 <asp:Button ID="AddButton" runat="server" CommandName="AddToCart" CommandArgument="" Text="Add to Cart" /> 为 GridView 控件的 RowCommand 事件创建一个方法。 在该方法中,执行下列操作: 检查事件参数对象的 CommandName 属性来查看传入什么字符串。 如果需要,使用 CommandArgument 属性检索包含该按钮的行的索引。 为用户单击的按钮执行相应的逻辑。 下面的示例演示响应 GridView 控件中的按钮单击的方法。 在该示例中,TemplateField 列中的按钮发送命令“AddToCart”。 RowCommand 事件处理程序确定被单击的按钮。 如果被单击的是购物车按钮,则代码执行相应的逻辑。
listview里的button事件添加方法
搞了很长时间了,如何在listview button上添加事件监听,一直是网友们比较在意的,本文将为您解答此疑惑,需要了解的朋友可以参考下
ASP.NET 中 Button、LinkButton和ImageButton 三种控件的使用详解
ASP.NET Framework包含三个用于向服务器端提交表单的控件:Button、LinkButton和ImageButton。这三个控件拥有同样的功能,但每种控件的外观界面不同。 本文就带着大家学习如何在页面中使用这三种控件。然后,学习如何关联客户端脚本和服务器端Button控件,以及如何使用Button控件把一个表单传到不是当前页的页面。最后,学习如何处理Button控件的Command事件。 一、使用Button控件 Button控件用来向服务器端提交表单的按钮。例如,代码清单1中的页面包含一个Button控件。点击这个Button控件,则更新由Label控件显示的时间(见图1)。
ASP.NET基本服务器控件.ppt
ASP.NET基本服务器控件.pptASP.NET基本服务器控件.pptASP.NET基本服务器控件.ppt


