I can not edit in the code behind anything that is between the itemtemplate










0














I need to access in the code behind some labels that are inside an ITEMTEMPLATE, I can not even apply RUNAT = SERVER and put an ID !! in fact, nothing that is inside the ITEMTEMPLATE I can access in the code behind! I need the listview + item template PRA to display some information from my database, but I also need to add and manipulate some labels, how should I do this?



MY CODE :



 <div class="row">
<div class="col-lg-12">

<asp:ListView ID="lv_post" runat="server">

<ItemTemplate runat="server">
<div class="row">
<div class="col-lg-12">
<h2 class="titulo"><b><%# Eval("titulo")%></b></h2>
</div>

<div class="col-lg-12">
<div class="data" style="margin-bottom: 1px;"><i class="far fa-calendar-alt"></i><%# Eval("data") %> <i class="fas fa-user"></i><%# Eval("autor") %></div>
</div>

<div class="col-lg-12" style="margin-bottom: 8px;">
<asp:Label ID="lbl_estrela1" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela2" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela3" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela4" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela5" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
</div>

<div class="col-lg-12">
<p class="conteudo">"<%# Eval("conteudo") %>"</p>
</div>

</div>
<%--<%# Eval("id_categoria_fk") %>--%>
<hr />

</ItemTemplate>

</asp:ListView>

</div>
</div>


i can't acess this on code behind:



 <div class="col-lg-12" style="margin-bottom: 8px;">
<asp:Label ID="lbl_estrela1" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela2" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela3" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela4" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela5" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
</div>


if I move out of ITEMTEMPLATE I can, but I need this information in the middle of information that only appears in the itemtemplate.










share|improve this question

















  • 1




    You need to access the items by the ItemTemplate Index because there can be more than one control: var lbl = lv_post.FindControl("lbl_estrela1") as Label;
    – VDWWD
    Nov 12 at 7:33










  • i can for exemple change the style of a label using this ? how? For what I saw you are getting the value of the label and putting it in the var, but I had to manipulate the attributes of the label!
    – Wellington Capoia
    Nov 12 at 13:14











  • You can, lbl is typeof Label. so it has all the properties.
    – VDWWD
    Nov 12 at 13:24











  • i use var lbl1 = lv_post.FindControl("lbl_estrela1") as Label; so i try lbl1.Attributes.Add("style", "color: #d40000;"); and give me exception System.NullReferenceException: Object reference not set to an instance of an object.'
    – Wellington Capoia
    Nov 12 at 14:52
















0














I need to access in the code behind some labels that are inside an ITEMTEMPLATE, I can not even apply RUNAT = SERVER and put an ID !! in fact, nothing that is inside the ITEMTEMPLATE I can access in the code behind! I need the listview + item template PRA to display some information from my database, but I also need to add and manipulate some labels, how should I do this?



MY CODE :



 <div class="row">
<div class="col-lg-12">

<asp:ListView ID="lv_post" runat="server">

<ItemTemplate runat="server">
<div class="row">
<div class="col-lg-12">
<h2 class="titulo"><b><%# Eval("titulo")%></b></h2>
</div>

<div class="col-lg-12">
<div class="data" style="margin-bottom: 1px;"><i class="far fa-calendar-alt"></i><%# Eval("data") %> <i class="fas fa-user"></i><%# Eval("autor") %></div>
</div>

<div class="col-lg-12" style="margin-bottom: 8px;">
<asp:Label ID="lbl_estrela1" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela2" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela3" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela4" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela5" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
</div>

<div class="col-lg-12">
<p class="conteudo">"<%# Eval("conteudo") %>"</p>
</div>

</div>
<%--<%# Eval("id_categoria_fk") %>--%>
<hr />

</ItemTemplate>

</asp:ListView>

</div>
</div>


i can't acess this on code behind:



 <div class="col-lg-12" style="margin-bottom: 8px;">
<asp:Label ID="lbl_estrela1" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela2" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela3" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela4" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela5" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
</div>


if I move out of ITEMTEMPLATE I can, but I need this information in the middle of information that only appears in the itemtemplate.










share|improve this question

















  • 1




    You need to access the items by the ItemTemplate Index because there can be more than one control: var lbl = lv_post.FindControl("lbl_estrela1") as Label;
    – VDWWD
    Nov 12 at 7:33










  • i can for exemple change the style of a label using this ? how? For what I saw you are getting the value of the label and putting it in the var, but I had to manipulate the attributes of the label!
    – Wellington Capoia
    Nov 12 at 13:14











  • You can, lbl is typeof Label. so it has all the properties.
    – VDWWD
    Nov 12 at 13:24











  • i use var lbl1 = lv_post.FindControl("lbl_estrela1") as Label; so i try lbl1.Attributes.Add("style", "color: #d40000;"); and give me exception System.NullReferenceException: Object reference not set to an instance of an object.'
    – Wellington Capoia
    Nov 12 at 14:52














0












0








0







I need to access in the code behind some labels that are inside an ITEMTEMPLATE, I can not even apply RUNAT = SERVER and put an ID !! in fact, nothing that is inside the ITEMTEMPLATE I can access in the code behind! I need the listview + item template PRA to display some information from my database, but I also need to add and manipulate some labels, how should I do this?



MY CODE :



 <div class="row">
<div class="col-lg-12">

<asp:ListView ID="lv_post" runat="server">

<ItemTemplate runat="server">
<div class="row">
<div class="col-lg-12">
<h2 class="titulo"><b><%# Eval("titulo")%></b></h2>
</div>

<div class="col-lg-12">
<div class="data" style="margin-bottom: 1px;"><i class="far fa-calendar-alt"></i><%# Eval("data") %> <i class="fas fa-user"></i><%# Eval("autor") %></div>
</div>

<div class="col-lg-12" style="margin-bottom: 8px;">
<asp:Label ID="lbl_estrela1" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela2" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela3" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela4" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela5" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
</div>

<div class="col-lg-12">
<p class="conteudo">"<%# Eval("conteudo") %>"</p>
</div>

</div>
<%--<%# Eval("id_categoria_fk") %>--%>
<hr />

</ItemTemplate>

</asp:ListView>

</div>
</div>


i can't acess this on code behind:



 <div class="col-lg-12" style="margin-bottom: 8px;">
<asp:Label ID="lbl_estrela1" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela2" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela3" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela4" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela5" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
</div>


if I move out of ITEMTEMPLATE I can, but I need this information in the middle of information that only appears in the itemtemplate.










share|improve this question













I need to access in the code behind some labels that are inside an ITEMTEMPLATE, I can not even apply RUNAT = SERVER and put an ID !! in fact, nothing that is inside the ITEMTEMPLATE I can access in the code behind! I need the listview + item template PRA to display some information from my database, but I also need to add and manipulate some labels, how should I do this?



MY CODE :



 <div class="row">
<div class="col-lg-12">

<asp:ListView ID="lv_post" runat="server">

<ItemTemplate runat="server">
<div class="row">
<div class="col-lg-12">
<h2 class="titulo"><b><%# Eval("titulo")%></b></h2>
</div>

<div class="col-lg-12">
<div class="data" style="margin-bottom: 1px;"><i class="far fa-calendar-alt"></i><%# Eval("data") %> <i class="fas fa-user"></i><%# Eval("autor") %></div>
</div>

<div class="col-lg-12" style="margin-bottom: 8px;">
<asp:Label ID="lbl_estrela1" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela2" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela3" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela4" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela5" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
</div>

<div class="col-lg-12">
<p class="conteudo">"<%# Eval("conteudo") %>"</p>
</div>

</div>
<%--<%# Eval("id_categoria_fk") %>--%>
<hr />

</ItemTemplate>

</asp:ListView>

</div>
</div>


i can't acess this on code behind:



 <div class="col-lg-12" style="margin-bottom: 8px;">
<asp:Label ID="lbl_estrela1" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela2" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela3" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela4" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
<asp:Label ID="lbl_estrela5" CssClass="fa fa-star" runat="server" Text=""></asp:Label>
</div>


if I move out of ITEMTEMPLATE I can, but I need this information in the middle of information that only appears in the itemtemplate.







asp.net listview webforms itemtemplate






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 4:22









Wellington Capoia

102




102







  • 1




    You need to access the items by the ItemTemplate Index because there can be more than one control: var lbl = lv_post.FindControl("lbl_estrela1") as Label;
    – VDWWD
    Nov 12 at 7:33










  • i can for exemple change the style of a label using this ? how? For what I saw you are getting the value of the label and putting it in the var, but I had to manipulate the attributes of the label!
    – Wellington Capoia
    Nov 12 at 13:14











  • You can, lbl is typeof Label. so it has all the properties.
    – VDWWD
    Nov 12 at 13:24











  • i use var lbl1 = lv_post.FindControl("lbl_estrela1") as Label; so i try lbl1.Attributes.Add("style", "color: #d40000;"); and give me exception System.NullReferenceException: Object reference not set to an instance of an object.'
    – Wellington Capoia
    Nov 12 at 14:52













  • 1




    You need to access the items by the ItemTemplate Index because there can be more than one control: var lbl = lv_post.FindControl("lbl_estrela1") as Label;
    – VDWWD
    Nov 12 at 7:33










  • i can for exemple change the style of a label using this ? how? For what I saw you are getting the value of the label and putting it in the var, but I had to manipulate the attributes of the label!
    – Wellington Capoia
    Nov 12 at 13:14











  • You can, lbl is typeof Label. so it has all the properties.
    – VDWWD
    Nov 12 at 13:24











  • i use var lbl1 = lv_post.FindControl("lbl_estrela1") as Label; so i try lbl1.Attributes.Add("style", "color: #d40000;"); and give me exception System.NullReferenceException: Object reference not set to an instance of an object.'
    – Wellington Capoia
    Nov 12 at 14:52








1




1




You need to access the items by the ItemTemplate Index because there can be more than one control: var lbl = lv_post.FindControl("lbl_estrela1") as Label;
– VDWWD
Nov 12 at 7:33




You need to access the items by the ItemTemplate Index because there can be more than one control: var lbl = lv_post.FindControl("lbl_estrela1") as Label;
– VDWWD
Nov 12 at 7:33












i can for exemple change the style of a label using this ? how? For what I saw you are getting the value of the label and putting it in the var, but I had to manipulate the attributes of the label!
– Wellington Capoia
Nov 12 at 13:14





i can for exemple change the style of a label using this ? how? For what I saw you are getting the value of the label and putting it in the var, but I had to manipulate the attributes of the label!
– Wellington Capoia
Nov 12 at 13:14













You can, lbl is typeof Label. so it has all the properties.
– VDWWD
Nov 12 at 13:24





You can, lbl is typeof Label. so it has all the properties.
– VDWWD
Nov 12 at 13:24













i use var lbl1 = lv_post.FindControl("lbl_estrela1") as Label; so i try lbl1.Attributes.Add("style", "color: #d40000;"); and give me exception System.NullReferenceException: Object reference not set to an instance of an object.'
– Wellington Capoia
Nov 12 at 14:52





i use var lbl1 = lv_post.FindControl("lbl_estrela1") as Label; so i try lbl1.Attributes.Add("style", "color: #d40000;"); and give me exception System.NullReferenceException: Object reference not set to an instance of an object.'
– Wellington Capoia
Nov 12 at 14:52













1 Answer
1






active

oldest

votes


















0














ListView contains a list of items. The ItemTemplate describes the layout of each one of these items. So, the Label controls inside the template exist for every item of the list.



Here is a working example:



ASPX Page



<head runat="server">
<title></title>
<style>
.color2
color: #d40000;

</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="lv_post" runat="server" ItemType="String">
<ItemTemplate>
<asp:Label ID="lbl_estrela" runat="server" Text="<%# Item %>"></asp:Label>
<br />
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>


Code Behind



public string data = "Data 1", "Data 2", "Data 3", "Data 4" ;

protected void Page_Load(object sender, EventArgs e)

if (!IsPostBack)

lv_post.DataSource = data;
lv_post.DataBind();

var lbl_estrela1 = lv_post.Items[1].FindControl("lbl_estrela") as Label;
lbl_estrela1.CssClass = "color2";

var lbl_estrela3 = lv_post.Items[3].FindControl("lbl_estrela") as Label;
lbl_estrela3.CssClass = "color2";




In the above example, the css style of the second and the fourth label is set to color2. Note, the use of the Items collection.



Optional



To better understand, take a look at the page source generated when the page is loaded.



<div> 
<span id="lv_post_lbl_estrela_0">Data 1</span>
<br />

<span id="lv_post_lbl_estrela_1" class="color2">Data 2</span>
<br />

<span id="lv_post_lbl_estrela_2">Data 3</span>
<br />

<span id="lv_post_lbl_estrela_3" class="color2">Data 4</span>
<br />
</div>





share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255935%2fi-can-not-edit-in-the-code-behind-anything-that-is-between-the-itemtemplate%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    ListView contains a list of items. The ItemTemplate describes the layout of each one of these items. So, the Label controls inside the template exist for every item of the list.



    Here is a working example:



    ASPX Page



    <head runat="server">
    <title></title>
    <style>
    .color2
    color: #d40000;

    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:ListView ID="lv_post" runat="server" ItemType="String">
    <ItemTemplate>
    <asp:Label ID="lbl_estrela" runat="server" Text="<%# Item %>"></asp:Label>
    <br />
    </ItemTemplate>
    </asp:ListView>
    </div>
    </form>
    </body>


    Code Behind



    public string data = "Data 1", "Data 2", "Data 3", "Data 4" ;

    protected void Page_Load(object sender, EventArgs e)

    if (!IsPostBack)

    lv_post.DataSource = data;
    lv_post.DataBind();

    var lbl_estrela1 = lv_post.Items[1].FindControl("lbl_estrela") as Label;
    lbl_estrela1.CssClass = "color2";

    var lbl_estrela3 = lv_post.Items[3].FindControl("lbl_estrela") as Label;
    lbl_estrela3.CssClass = "color2";




    In the above example, the css style of the second and the fourth label is set to color2. Note, the use of the Items collection.



    Optional



    To better understand, take a look at the page source generated when the page is loaded.



    <div> 
    <span id="lv_post_lbl_estrela_0">Data 1</span>
    <br />

    <span id="lv_post_lbl_estrela_1" class="color2">Data 2</span>
    <br />

    <span id="lv_post_lbl_estrela_2">Data 3</span>
    <br />

    <span id="lv_post_lbl_estrela_3" class="color2">Data 4</span>
    <br />
    </div>





    share|improve this answer

























      0














      ListView contains a list of items. The ItemTemplate describes the layout of each one of these items. So, the Label controls inside the template exist for every item of the list.



      Here is a working example:



      ASPX Page



      <head runat="server">
      <title></title>
      <style>
      .color2
      color: #d40000;

      </style>
      </head>
      <body>
      <form id="form1" runat="server">
      <div>
      <asp:ListView ID="lv_post" runat="server" ItemType="String">
      <ItemTemplate>
      <asp:Label ID="lbl_estrela" runat="server" Text="<%# Item %>"></asp:Label>
      <br />
      </ItemTemplate>
      </asp:ListView>
      </div>
      </form>
      </body>


      Code Behind



      public string data = "Data 1", "Data 2", "Data 3", "Data 4" ;

      protected void Page_Load(object sender, EventArgs e)

      if (!IsPostBack)

      lv_post.DataSource = data;
      lv_post.DataBind();

      var lbl_estrela1 = lv_post.Items[1].FindControl("lbl_estrela") as Label;
      lbl_estrela1.CssClass = "color2";

      var lbl_estrela3 = lv_post.Items[3].FindControl("lbl_estrela") as Label;
      lbl_estrela3.CssClass = "color2";




      In the above example, the css style of the second and the fourth label is set to color2. Note, the use of the Items collection.



      Optional



      To better understand, take a look at the page source generated when the page is loaded.



      <div> 
      <span id="lv_post_lbl_estrela_0">Data 1</span>
      <br />

      <span id="lv_post_lbl_estrela_1" class="color2">Data 2</span>
      <br />

      <span id="lv_post_lbl_estrela_2">Data 3</span>
      <br />

      <span id="lv_post_lbl_estrela_3" class="color2">Data 4</span>
      <br />
      </div>





      share|improve this answer























        0












        0








        0






        ListView contains a list of items. The ItemTemplate describes the layout of each one of these items. So, the Label controls inside the template exist for every item of the list.



        Here is a working example:



        ASPX Page



        <head runat="server">
        <title></title>
        <style>
        .color2
        color: #d40000;

        </style>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>
        <asp:ListView ID="lv_post" runat="server" ItemType="String">
        <ItemTemplate>
        <asp:Label ID="lbl_estrela" runat="server" Text="<%# Item %>"></asp:Label>
        <br />
        </ItemTemplate>
        </asp:ListView>
        </div>
        </form>
        </body>


        Code Behind



        public string data = "Data 1", "Data 2", "Data 3", "Data 4" ;

        protected void Page_Load(object sender, EventArgs e)

        if (!IsPostBack)

        lv_post.DataSource = data;
        lv_post.DataBind();

        var lbl_estrela1 = lv_post.Items[1].FindControl("lbl_estrela") as Label;
        lbl_estrela1.CssClass = "color2";

        var lbl_estrela3 = lv_post.Items[3].FindControl("lbl_estrela") as Label;
        lbl_estrela3.CssClass = "color2";




        In the above example, the css style of the second and the fourth label is set to color2. Note, the use of the Items collection.



        Optional



        To better understand, take a look at the page source generated when the page is loaded.



        <div> 
        <span id="lv_post_lbl_estrela_0">Data 1</span>
        <br />

        <span id="lv_post_lbl_estrela_1" class="color2">Data 2</span>
        <br />

        <span id="lv_post_lbl_estrela_2">Data 3</span>
        <br />

        <span id="lv_post_lbl_estrela_3" class="color2">Data 4</span>
        <br />
        </div>





        share|improve this answer












        ListView contains a list of items. The ItemTemplate describes the layout of each one of these items. So, the Label controls inside the template exist for every item of the list.



        Here is a working example:



        ASPX Page



        <head runat="server">
        <title></title>
        <style>
        .color2
        color: #d40000;

        </style>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>
        <asp:ListView ID="lv_post" runat="server" ItemType="String">
        <ItemTemplate>
        <asp:Label ID="lbl_estrela" runat="server" Text="<%# Item %>"></asp:Label>
        <br />
        </ItemTemplate>
        </asp:ListView>
        </div>
        </form>
        </body>


        Code Behind



        public string data = "Data 1", "Data 2", "Data 3", "Data 4" ;

        protected void Page_Load(object sender, EventArgs e)

        if (!IsPostBack)

        lv_post.DataSource = data;
        lv_post.DataBind();

        var lbl_estrela1 = lv_post.Items[1].FindControl("lbl_estrela") as Label;
        lbl_estrela1.CssClass = "color2";

        var lbl_estrela3 = lv_post.Items[3].FindControl("lbl_estrela") as Label;
        lbl_estrela3.CssClass = "color2";




        In the above example, the css style of the second and the fourth label is set to color2. Note, the use of the Items collection.



        Optional



        To better understand, take a look at the page source generated when the page is loaded.



        <div> 
        <span id="lv_post_lbl_estrela_0">Data 1</span>
        <br />

        <span id="lv_post_lbl_estrela_1" class="color2">Data 2</span>
        <br />

        <span id="lv_post_lbl_estrela_2">Data 3</span>
        <br />

        <span id="lv_post_lbl_estrela_3" class="color2">Data 4</span>
        <br />
        </div>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 at 15:31









        dpant

        516516




        516516



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255935%2fi-can-not-edit-in-the-code-behind-anything-that-is-between-the-itemtemplate%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3