Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.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# 在图像上检索ASP.NET评估按钮单击_C#_Asp.net_Repeater_Imagebutton_Databinder - Fatal编程技术网

C# 在图像上检索ASP.NET评估按钮单击

C# 在图像上检索ASP.NET评估按钮单击,c#,asp.net,repeater,imagebutton,databinder,C#,Asp.net,Repeater,Imagebutton,Databinder,我有下面的中继器,带有一些包含信息的div和一个ImageButton。单击ImageButton,我想检索包含ID的DataBinder.Eval 但是,由于它是图像按钮RepeaterItemEventArgs只能是图像ClickEventArgs,因为它是图像按钮,因此我不知道如何准确检索id。将id为的隐藏字段添加到Repeater: <asp:HiddenField ID="hfId" runat="server" Value='<%# Eval("ID") %>'

我有下面的中继器,带有一些包含信息的div和一个ImageButton。单击ImageButton,我想检索包含ID的DataBinder.Eval


但是,由于它是图像按钮RepeaterItemEventArgs只能是图像ClickEventArgs,因为它是图像按钮,因此我不知道如何准确检索id。

将id为的隐藏字段添加到Repeater:

<asp:HiddenField ID="hfId" runat="server" Value='<%# Eval("ID") %>' />
您还可以在CommandArgument中添加id作为


如果您想在Repeater、DataGrid或GridViews中查找实现InAdminContainer接口的父行,那么最好在.parent.com上使用.NamingContainer,而不是.parent.com。尝试了此操作,但字符串id为空
  protected void btnPrint_Click(object sender, RepeaterItemEventArgs e)
    {
        var id = e.Item.FindControl("Id") as Label;
        DefaultClass.createPDF(Convert.ToInt32(id));
    }
<asp:HiddenField ID="hfId" runat="server" Value='<%# Eval("ID") %>' />
var id = ((Control)sender).Parent.FindControl("hfId") as HiddenField;
DefaultClass.createPDF(Convert.ToInt32(id.Value));
<asp:ImageButton runat="server" ID="btnPrint" ImageUrl="~/Images/print.gif" OnClick="btnPrint_Click" CommandArgument = '<%# Eval("ID") %>'/>
protected void btnPrint_Click(object sender, EventArgs e)
{
   string id = (sender as ImageButton).CommandArgument;
}