在我的数据列表中我有一个(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>
答案 0 :(得分:0)
尝试这样的事情:
Control theDiv = e.Item.FindControl("divPostComment");
if (theDiv != null) theDiv.Visible = true;