locked
How can i change span's class in C# ? RRS feed

  • Question

  • User-1598123975 posted

    the following code is under gridview1, can't get the span's ID directly so i use findcontrol instead

    <asp:TemplateField HeaderText="Reply">
    <ItemTemplate>
    <span id="convertsantionCount" class="label label-success"><%# Portal.Message.getConversationCount(Eval("ID").ToString())%></span>
    </ItemTemplate>
    </asp:TemplateField>

    System.Web.UI.HtmlControls.HtmlGenericControl control = (System.Web.UI.HtmlControls.HtmlGenericControl) GridView1.FindControl("convertsantionCount");
    control.Attributes["class"] = "badge badge-warning";

    it says the control.Attributes["class"] Object reference not set to an instance of an object.

    anyone would tell me how can i mannually change the class of the span. any way would do much thanks.

    Wednesday, November 27, 2013 11:57 PM

All replies

  • User1119594843 posted

    Hi,

    Is possible for you to try with asp:Label. After rendering asp:Label will be as span tag until we assign the AssociatedControlID it will be span. when we assign AssociatedControlID it will be render as label.

    Thursday, November 28, 2013 12:24 AM
  • User555306248 posted

    add runat=server to span

    Thursday, November 28, 2013 10:39 PM
  • User-1598123975 posted

    doesnt work its inside lots of layers 

    cant even use find control thanks for reply

    Wednesday, December 4, 2013 11:01 PM