使用按钮单击执行ASP.net C#gridview
这似乎很简单,但就我个人而言,我不知道它是如何工作的 我有一个使用按钮单击执行ASP.net C#gridview,c#,asp.net,gridview,C#,Asp.net,Gridview,这似乎很简单,但就我个人而言,我不知道它是如何工作的 我有一个gridview 我有一个标准按钮 如何使用按钮单击来显示gridview 有什么建议吗?这是MSDN页面上的一个简短示例:() 您可以在GridView中添加asp:TemplateField,并通过按钮中的CommandArgument属性设置当前行索引 <asp:TemplateField> <ItemTemplate> <asp:Button ID="AddButton" runat=
gridview
我有一个标准按钮
如何使用按钮单击来显示gridview
有什么建议吗?这是MSDN页面上的一个简短示例:() 您可以在
GridView
中添加asp:TemplateField
,并通过按钮中的CommandArgument属性设置当前行索引
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="AddButton" runat="server"
CommandName="AddToCart"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
Text="Add to Cart" />
</ItemTemplate>
</asp:TemplateField>
希望这能对您有所帮助。执行gridview的定义是什么?对不起,我想这个词选得不好。我想用点击按钮来显示gridview。这都是好东西。我想出了怎么做我想做的事。我正想好好想想。我只需将GridView.Visible设置为“false”,然后使用按钮单击事件使其再次可见。
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
if (e.CommandName == "AddToCart") {
// Retrieve the row index stored in the
// CommandArgument property.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button
// from the Rows collection.
GridViewRow row = GridView1.Rows[index];
// Add code here to add the item to the shopping cart.
}
}