[英]How to pass CommandName of LinkButton in GridView to OnClick event
[英]LinkButton CommandName not working
我在gridview中有一个链接按钮(链接按钮的文本是edit),我给它一个命令名调用Modify
所以在我的设计中,代码是:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="modify">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
在我的代码后面是:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
LinkButton linkBtn = (LinkButton)sender;
if (linkBtn.CommandName == "modify") // tried linkBtn.CommandArguemtn , doesn't help
{
Panel1.Visible = true;
int index = Convert.ToInt32(e.CommandArgument);
Label login = (Label)GridView1.Rows[index].Cells[0].FindControl("Label1");
//Things i want to do
}
}
如您所见,我将面板设置为可见,但不会出现...我的方法正确吗? 我知道另一种选择是使用生成的默认编辑按钮,但是我不想这样做。 我试图将链接按钮放在gridview中,然后单击链接按钮,然后应该出现面板(由文本框控件组成),然后在面板中更改gridview数据。
只是使用
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "modify")
{
Panel1.Visible = true;
int index = Convert.ToInt32(e.CommandArgument);
Label login = (Label)GridView1.Rows[index].Cells[0].FindControl("Label1");
//Things i want to do
}
}
您无需先检查按钮, e.CommandName
就足够了
尝试这样。使用CommandName
属性指定或确定命令名称MSDN
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="modify")
{
\\
}
}
使用以下代码
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToLower()== "modify")
{
Panel1.Visible = true;
int index = Convert.ToInt32(e.CommandArgument);
Label login = (Label)GridView1.Rows[index].Cells[0].FindControl("Label1");
//Things i want to do
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.