HShbib
HShbib

Reputation: 1841

Binding data to a Button in repeater

I have a repeater which has a hidden field of Parking_ID <asp:HiddenField Value='<%# Eval("Parking_ID") %>' ID="HiddenField1" runat="server" /> and a Button under it.

I tried binding the value to the button from the html, it is giving me an error which indicates binding did not work. The programming language for the form is C#

How can I bind the value of Parking_ID with its button in order to pass that value to another form? and how it can be passed to the other form?

Regards.

Upvotes: 1

Views: 2676

Answers (1)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

Why not directly set the value to the button's CommandArgument property ?

For example...

<asp:Button ID="Button1" runat="server" Text="Button" CommandArgument='<%# Eval("Parking_ID") %>' />

And then in the code behind...

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    Int32 value = Convert.ToInt32(e.CommandArgument);
    Response.Redirect("URL?id=" + value.ToString());
}

Upvotes: 1

Related Questions