在我的数据列表中,我有一个 (div),它的 id 是 divpost,它的可见性是错误的。现在我喜欢在 datalist_databound 中找到它,如果条件正常,可见性将是真实的。
所以我使用了下面的代码,但我不知道我必须如何找到(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>