I have a commandargument inside an aspx page set for an object variable inside a for loop, as shown below:
<% foreach (PromotionImage p in imageList)
{
%>
<asp:LinkButton runat="server" OnCommand="deleteButton_Click" ID="deleteButton" CommandArgument="<%# p.ImageId.ToString(); %>" ForeColor="Red"
OnClientClick="javascript:return confirm('Are you sure you want to delete this item?');">X</asp:LinkButton>
<%
}
%>
Then in my C # code, I have the following to try to get this value:
protected void deleteButton_Click(object sender, CommandEventArgs e)
{
int imageId = System.Convert.ToInt32(e.CommandArgument.ToString());
}
However, C # code continues to return "System.FormatException: the input line was not in the correct format."
When the e.CommandArgument debug contains the string "<% # p.ImageId.ToString ();%>" and not the actual ImageId, why doesn't it evaluate? Although all my other variables are well rated?
David source
share