我需要在我的代码后面将一个int参数传递给Onclick事件,在我的例子中,我试过这个:
<% for (int index = 0; index < UploadDocs.Count;index++ )
{
%>
<asp:ImageButton runat="server"
visible="false"
CommandArgument='<%=Eval("index")%>'
ID="Btn_RemoveOtherPJ"
ImageUrl="~/Images/W4_remove.gif"
OnClick="RemoveAttachedDoc_Button_Click" /><%}%>
在我的代码后面:
protected void RemoveAttachedDoc_Button_Click(object source, EventArgs e)
{
try
{
ImageButton btn = (ImageButton)source;
int index = Int32.Parse(btn.CommandArgument);
UploadDocs.RemoveAt(index);
}
catch (Exception exception)
{
ImhotepHelper.ManagedError(exception, Context);
}
}
问题是CommandArgument不是作为字符串读取而不是int: enter image description here