Search code examples
asp.nethyperlinkcode-behind

how to integrate code behind variables to the linkbutton in the design view


I just need to use the count value which will be generated on the code behind page on the designer view :

public void BindCount()
{
    int count = caravans.GetNoOfCaravansGreater2000();
}

Designer View :

<asp:LinkButton ID="lnkPrice3" runat="server" CommandArgument="2000+" OnClick="lnkPrice3_Click">Greater than 2000(<%=count %>)</asp:LinkButton>

I tried the above syntax but it doesnt works, Any advice or suggestions will be highly appreciated


Solution

  • You need to set the Text property of your LinkButton dynamically.

    protected void Page_Load() {
    
       if(!Page.IsPostBack)
           SetCount();
    }
    
    private void SetCount()
    {
        int count = caravans.GetNoOfCaravansGreater2000();
        lnkPrice3.Text = string.Format("Greater than 2000({0})", count);
    }