Reputation: 34217
THE GOAL
To add a cssclass to a div that is inside a repeater if a bit column in sql table is true.
CURRENT CODE
<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
The repeater is correctly bound on page load and populated from an sp that includes the column 'MyBitCol'
QUESTIONS
How to find and target a div inside a repeater from code behind?
How to retrieve mssql column value bound to repeater? (Column is bound to repeater but not called on aspx page. Needs to be called in code behind).
Upvotes: 0
Views: 1280
Reputation: 3740
To find panel:
{
Dim pnlSubCategories As Panel = DirectCast(e.Item.FindControl("pnl1"),Panel)
pnlSubCategories.cssClass="yourclass"
}
Upvotes: 1