gpt4 book ai didi

asp.net - 如何在转发器中找到一个 div/panel 并应用 css?

转载 作者:太空宇宙 更新时间:2023-11-04 14:37:48 25 4
gpt4 key购买 nike

目标

如果 sql 表中的位列为真,则将 cssclass 添加到转发器内的 div。

当前代码

  <asp:Repeater ID="rpt1" RunAt="Server" OnItemDataBound="rpt1_ItemDataBound">
<ItemTemplate>
<asp:Panel ID="pnl1" RunAt="Server"></asp:Panel>
</ItemTemplate>
</asp:Repeater>

Protected Sub rpt1_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If e.Item.DataItem("MyBitCol") = True Then
Dim div1 = CType(rpt1.FindControl("pnl1"), Panel)
div1.Attributes.Add("class", "MyClass")
End If
End If
End Sub

转发器在页面加载时正确绑定(bind)并从包含“MyBitCol”列的 sp 填充

问题

如何从隐藏代码中查找并定位中继器内的 div?

如何检索绑定(bind)到中继器的 mssql 列值?(Column绑定(bind)了repeater,aspx页面没有调用,需要在code behind中调用)。

最佳答案

查找面板:

{
Dim pnlSubCategories As Panel = DirectCast(e.Item.FindControl("pnl1"),Panel)
pnlSubCategories.cssClass="yourclass"
}

关于asp.net - 如何在转发器中找到一个 div/panel 并应用 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18610768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com