I have a list of records. Each record has unique id and text. When I blow it on page, each record has a button, who refer to method DeleteRecord(object sender, EventArgs e). But this button's doesn't know record's id. I tried push id on CommandArgument, but it's doesn't works.
Is there is another way to solve this trouble, or I simply make mistake, when I fill CommandArgument?
Profile.aspx:
<%
foreach (DAL.Record record in records)
{
<b><% Response.Write(record.Text);%></b>
<asp:Button CommandArgument="<%#Eval("record.Id")%>" runat="server" OnClick="DeleteRecord" />
}
%>
When I pause my program on Profile.cs in method:
protected void DeleteRecord(object sender, EventArgs e)
(Button)sender.CommandArgument
Always == "";
The problem in
CommandArgument="<%#Eval("record.Id")%>", or my DNA.
Forgive me for my poor english.
You can't use inline scripts in server controls, that is:
<asp:Button CommandName="Delete" CommandArgument="<%#Eval("record.Id")%>" />
Is wrong, because you're trying to use server code in an attribute of a server control.
Instead of this, you either have to build the button manually (as an HTML control, not a server control), or you have to use a Repeater instead of foreach, and assign the CommandArgument in the repeater's ItemDataBound event handler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With