Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用按钮单击执行ASP.net C#gridview_C#_Asp.net_Gridview - Fatal编程技术网

使用按钮单击执行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.
    }
}