How to get text from Legend

3 posts, 0 answers
  1. Helen
    Helen avatar
    42 posts
    Member since:
    Nov 2013

    Posted 28 May 2014 Link to this post


    Hi,

    Could you show me how to get the innertext (company_name) from the legend in the ItemCommand event?  I tried the following, but the error is object reference not set.

    Here's the partial code that shows the legend:
    1.<ItemTemplate>
    2.    
    3.        <fieldset style="float:left; width: 480px; height:280px; margin:5px; ">
    4. 
    5.            <legend ID="companyName" style="color:darkblue; font-weight:bold">
    6.                      <%#Eval("company_name")%><img src="../../images/new1.png" style="width:15px;height:15px" />
    7.            </legend>

    Here's the code-behind

    01.protected void RadListView1_ItemCommand(object sender, RadListViewCommandEventArgs e)
    02.{
    03.    // TODO: need to pass leadid to main.
    04.    if (e.CommandName == "OpenDetail")
    05.    {
    06.        RadListViewDataItem item = e.ListViewItem as RadListViewDataItem;
    07.        string leadId = item.GetDataKeyValue("lead_id").ToString();
    08. 
    09.        //Label websitelabel = item.FindControl("WebsiteLabel") as Label;  // ** accesss ok **//
    10.         
    11.        // ** object reference not set **//
    12.        string leadName = (item.FindControl("companyName") as System.Web.UI.HtmlControls.HtmlGenericControl).InnerText;
    13. 
    14.        // ** Not working **//
    15.        //Hashtable table = new Hashtable();
    16.        //item.OwnerListView.ExtractValuesFromItem(table, item, true);
    17.        //string leadName = table["CompanyLegend"].ToString();
    18.        //string leadName = "ABC";
    19. 
    20.        OutcomeEventArgs outcomeEventArgs = new OutcomeEventArgs(leadId, leadName);
    21.        if (OpenLeadDetail != null)
    22.            OpenLeadDetail(this, outcomeEventArgs);
    23.    }
    24. 
    25.}

    Thank you,

    Helen

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 May 2014 in reply to Helen Link to this post

    Hi Helen,

    In order to access HTML controls in Server side code you have to set the runat property.  Please do the following modification in your ASPX which works fine at my end.

    ASPX:
    ...
    <
    legend id="companyName" runat="server" style="color: darkblue; font-weight: bold">
        <%#Eval("companyName")%><img src="../../images/new1.png" style="width: 15px; height: 15px" />
    </legend>
    ...

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Helen
    Helen avatar
    42 posts
    Member since:
    Nov 2013

    Posted 29 May 2014 in reply to Shinu Link to this post

    Shinu,

    Thx~ that was a stupid mistake on my part.

    Helen
Back to Top