2013-01-16 65 views
0

在我的數據列表中,我有一個(div),它的id是divpost,它的可見性是錯誤的。現在我想在datalist_databound中找到它,如果條件合適,可見性將爲true。我們如何才能在數據列表中找到div

所以我用下面的代碼,但我不知道如何找到(divpost)。

查找標籤或其他控件我沒有問題,根據下面的代碼,但對於div我不知道如何?

protected void DataList1_ItemDataBound 
(object sender, DataListItemEventArgs e) 
{ 


    var x = (Guid)(DataList1.DataKeys[e.Item.ItemIndex]); 
    Label labelstatus = (Label)e.Item.FindControl("lblstatus"); 
    Label labelcomment = (Label)e.Item.FindControl("lblcomment"); 
    BindLable(labelstatus,labelcomment, x); 


    var q3 = (from s in _DataContext.tblSends 


       where (s.DraftId == _Draftid) 

       select s.ToEmailId).Distinct(); 


    if ((Guid)q3.SingleOrDefault() == (Guid)Membership.GetUser().ProviderUserKey) 
    { 
     divpostcomment.visible = true; 
    } 

ASPX標記是象下面這樣:

<asp:DataList ID="DataList1" runat="server" DataKeyField="userid" 
    OnItemDataBound="DataList1_ItemDataBound" 
    > 
    <SeparatorStyle BorderStyle="Dotted" /> 
    <ItemTemplate> 
     <table class="style2"> 
      <tr> 
       <td> 

        <asp:Label ID="Label5" runat="server" Text='<%# "comments from "+Eval("username") %>'></asp:Label> 
        <asp:Label ID="lblStatus" runat="server" Text=""></asp:Label> 
        <br /> 

        <asp:Label ID="lblComment" runat="server" Text=""></asp:Label> 

        <div id="divPostComment" runat="server" visible="false"> 

         <asp:TextBox ID="txtComment" runat="server"></asp:TextBox> 
         <asp:FileUpload ID="FileUpload1" runat="server" /> 
         <asp:Button ID="btnUpload" runat="server" Text="Upload" /> 
         <asp:Button ID="pstComment" runat="server" Text="Post Comment" /> 

        </div> 
       </td> 
      </tr> 
      <tr> 
       <td> 



       </td> 
      </tr> 

回答

0

嘗試是這樣的:

Control theDiv = e.Item.FindControl("divPostComment"); 
if (theDiv != null) theDiv.Visible = true; 
相關問題