c# 4.0 - How to change value in listview of lable in asp.net -


hello need listview control here listview code below:

<asp:listview runat="server" id="listview1"           groupitemcount="3"   onitemcommand="listview1_itemcommand">                     <layouttemplate>                         <div>                             <asp:placeholder runat="server"                             id="groupplaceholder" />                         </div>                     </layouttemplate>                     <grouptemplate>                         <div style="clear: both;">                             <asp:placeholder runat="server"                                    id="itemplaceholder" />                         </div>                     </grouptemplate>                     <itemtemplate>                         <div class="store-l">                             <p class="exe-title">                                 <asp:label id="label1" runat="server">                              </asp:label>  </p>                             <center>              <a href="view.aspx?iv=<%# eval("id") %>"><asp:image id="image2"                    imageurl='<%# eval("imageurl")%>' runat="server"                                 height="175" width="280"></asp:image></a>      </center>                             <p class="exe-title">                                 <%# eval("description")%>                        <a href="viewresult.aspx?iv=<%# eval("id") %>">view result</a>                             </p>                                                    </div>                     </itemtemplate>                     <groupseparatortemplate>                         <div style="clear: both"/>                     </groupseparatortemplate>                     <emptydatatemplate>                     </emptydatatemplate>                 </asp:listview> 

there label1 want change value of via code. there 12 fixed values , need add these 12 values below:

1. day 1  2. day 2  3. day 3  4. day 4  5. day fiv etc. 

i want add value in lable1 using code. programming language c#. hope has solution doing please let me know how can , share code me

thank you

your basic approach should following:

in itemdatabound event handler listview, check see kind of template is. if itemtemplate, find control label1 using e.item.findcontrol("label1") , cast label type. free want. can assign label variable. should work:

protected void listview1_itemdatabound(object sender, listviewitemeventargs e) {     label label1 = (label)e.item.findcontrol("label1");      label1.text = "day 1"; //do whatever want label here } 

also, have hook listview event handler either in declarative markup or in page_load or event. if in declarative markup, add following attribute listview tag:

onitemdatabound="listview1_itemdatabound" 

hope helps.

check out link example:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemdatabound.aspx


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -