Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.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
C# “如何访问”;命令名";Gridview的页脚模板中定义了哪个?_C#_Asp.net_Gridview_.net 2.0_Rowcommand - Fatal编程技术网

C# “如何访问”;命令名";Gridview的页脚模板中定义了哪个?

C# “如何访问”;命令名";Gridview的页脚模板中定义了哪个?,c#,asp.net,gridview,.net-2.0,rowcommand,C#,Asp.net,Gridview,.net 2.0,Rowcommand,所以我有一个gridview,在FooterTemplate中我为ButtonAdd定义了一个commandname。下面是代码: <asp:TemplateField> <HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" VerticalA

所以我有一个gridview,在FooterTemplate中我为ButtonAdd定义了一个commandname。下面是代码:

                                      <asp:TemplateField>
                                    <HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" VerticalAlign="Top"></HeaderStyle>
                                    <FooterTemplate><asp:LinkButton CommandName="Insert" Text="Add credit" ID="btnAdd" OnClick="btnAdd_Click" Runat="server" Font-Size="XX-Small  "
                                            Font-Names="Verdana" Font-Bold="True" ForeColor="#5BB1E6" Width="7%"></asp:LinkButton>
                                    </FooterTemplate>
                                </asp:TemplateField>
等等。问题是,当我尝试访问e.rowcommand时,它不会捕获e之后的commandname

我的目标是能够在函数中读取e.commandname的值,非常感谢您的帮助。 非常感谢大家:)

将其更改为:

<asp:LinkButton CommandName="Insert" Text="Add credit" ID="btnAdd" OnCommand="btnAdd_Click" Runat="server" Font-Size="XX-Small  "
                                        Font-Names="Verdana" Font-Bold="True" ForeColor="#5BB1E6" Width="7%"></asp:LinkButton>

如果您想捕获CommandName和CommandArgument,您需要使用OnCommand事件,而不是OnClick。

当您说“它在e之后不捕获CommandName”时,您的意思是什么?你有编译错误吗?一个空引用错误?你的问题解决了吗?是的,非常感谢大家。谢谢给我加分的人。我以为这个问题进入了深渊哈哈。
<asp:LinkButton CommandName="Insert" Text="Add credit" ID="btnAdd" OnCommand="btnAdd_Click" Runat="server" Font-Size="XX-Small  "
                                        Font-Names="Verdana" Font-Bold="True" ForeColor="#5BB1E6" Width="7%"></asp:LinkButton>
public void btnAdd_Click(object sender, CommandEventArgs e)
{
    string sCommandName = e.CommandName;
}