2013-07-25 23 views
1

你好,我需要用ListView控件 這裏幫助如下列表視圖代碼:如何在asp.net改變拉布勒的列表視圖值

<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> 

有Label1的我想通過代碼來改變這個值。有12個固定值,我需要這12個值添加如下:

1. day 1 
2. day two 
3. day three 
4. day four 
5. day fiv etc. 

我想用代碼lable1添加此值。編程語言是c#。希望有人已經這樣做,請讓我知道我能做到這一點,和我分享你的代碼

謝謝

+0

你嘗試過這麼遠。爲什麼我們應該分享我們的代碼,拿出你的嘗試。 – Guanxi

回答

0

你的基本方法應該像下面這樣的解決方案:

在ItemDataBound事件ListView的處理程序,檢查它是什麼樣的模板。如果它是一個ItemTemplate,則使用e.Item.FindControl(「Label1」)查找控件Label1並將其轉換爲Label類型。然後你可以自由地處理你想要的東西。所以你可以將它分配給一個Label變量。像這樣的東西應該工作:

protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e) 
{ 
    Label Label1 = (Label)e.Item.FindControl("Label1"); 

    Label1.Text = "day 1"; //do whatever you want with the Label here 
} 

此外,你必須以關聯的ListView與無論是在聲明標記或在Page_Load中或其他事件此事件處理程序。如果你使用聲明性標記,只需將以下屬性添加到ListView標記中即可:

OnItemDataBound="ListView1_ItemDataBound" 

希望有所幫助。

退房這個環節爲例:

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

+0

,我知道,但我沒有得到如何改變曾經的行標籤值的價值 – Vikram

+1

謝謝你Anshul – Vikram