我想通过点击链接按钮来检索标签字段的值。它只能在onclick事件中被触发。我试过这个,但它给出了空值。
protected void verifycount_Click(object sender, EventArgs e)
{
GridViewRow link = ((LinkButton)sender).NamingContainer as GridViewRow;
Label qrcode = (Label)link.FindControl("lblqrcode");
string result=qrcode.text;
}
请帮忙解决这个问题
答案 0 :(得分:0)
protected void verifycount_Click(object sender, EventArgs e)
{
LinkButton Lnk = (LinkButton)sender;
string result=Lnk.Text;
}
答案 1 :(得分:0)
在网格视图列中的链接按钮中,作为命令参数,在该字段中发送标签值。您知道
<asp:BoundField DataField="FileName" HeaderText="Attached Files" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID = "lnkDelete" Text = "Delete" CommandArgument = '<%# Eval("FileName") %>'
runat = "server" OnClick = "DeleteHWAttachment" />
</ItemTemplate>
</asp:TemplateField>
然后你的代码就是这样,
protected void DeleteHWAttachment(object sender, EventArgs e)
{
string filename = (sender as LinkButton).CommandArgument;
}
答案 2 :(得分:0)
protected void verifycount_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string qrcode = grdrow.Cells[0].Text;
}
确保所有字段都是除linkbutton
之外的绑定字段