DAUD WANI DAUD WANI - 1 month ago 9
C# Question

How to pass data to Link button onclick event

/*help me i am stuck here on how to pass <%# DataBinder.Eval(Container.DataItem, "Site_No") %> as parm to link button when clicked */

<ItemTemplate >

<!-- small box -->
<div class='<%# DataBinder.Eval(Container.DataItem, "Status") %>'>
<div class="inner">

<h3><asp:Label ID="lblSiteNo" runat="server"><%# DataBinder.Eval(Container.DataItem, "Site_No") %><sup style="font-size: 20px"></sup></asp:Label></h3>

<p><%# DataBinder.Eval(Container.DataItem, "Site_Size") %></p>

<asp:LinkButton ID="LinkButton1" CssClass="small-box-footer" OnClick="" runat="server">More info</asp:LinkButton>




Instead of using OnClick event, use the CommandName and CommandArgument properties.

<asp:LinkButton ID="LinkButton1"  CssClass="small-box-footer" CommandName="MoreInfo_Command" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "PARAM_NAME") %>'  runat="server">More info</asp:LinkButton>

In your code behind:

      void MoreInfo_Command(Object sender, CommandEventArgs e) 
         string parameter = e.CommandArgument;