C# “如何访问”;命令名";Gridview的页脚模板中定义了哪个?
所以我有一个gridview,在FooterTemplate中我为ButtonAdd定义了一个commandname。下面是代码: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
<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;
}