Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ItemDataBound for nested datalist?

Status
Not open for further replies.

jkelly295

MIS
Aug 14, 2001
15
US
I have a repeater that has a placeholder inside it. I am assigning a datalist to the placehoder and setting the datasource inside the itemdatabound of the repeater. I also have a need to so some decision making inside the itemdatabound of the datalist. How do I hook up an ItemDataBound sub to a nested datalist?



<asp:Repeater ID="stepRepeater" Runat="server">
<ItemTemplate>
<tr>
<td align="center" width="5%" style="font-size:8pt;font-family:Arial;"><asp:Label ID="stepLabel" runat="server"/></td>
<td width="95%">
<asp:placeholder ID="oPlaceHolder" Runat="server">
</asp:placeholder>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>




Private Sub stepRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles stepRepeater.ItemDataBound

Dim stepLabel As Label = CType(e.Item.FindControl("stepLabel"), Label)
Dim oPlaceHolder As PlaceHolder = CType(e.Item.FindControl("oPlaceHolder"), PlaceHolder)


If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
stepLabel.Text = "<b>Step " & e.Item.DataItem("EntStep") & "</b><br>"
stepLabel.Text += "Choose <br>"
stepLabel.Text += "<b>" & Replace(e.Item.DataItem("EntOptionType"), "_", " ") & "</b>"


Dim thisList As New DataList

Dim oSQL As String


oSQL = "Exec getMeSomeData "


Dim oCommand As New OdbcCommand(oSQL, dbConn2)
Dim oReader As OdbcDataReader
oReader = oCommand.ExecuteReader
thisList.DataSource = oReader
thisList.DataBind()

'HOW DO I HOOK thisList to the ItemDataBound
'FUNCTION BELOW

oPlaceHolder.Controls.Add(thisList)
oReader.Close()

End If
End Sub


Private Sub thisList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles thisList.ItemDataBound
'NOTE: THE HANDLES THISLIST.ITEMDATABOUND gives an error.
End Sub
 
Try looking at the AddHandler function


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I ended up adding the datalist directly to the repeater on the aspx page (and added an OnItemDataBound="MyDataListBoundHandler()" and did not use the placeholder. The reply above would work great if I did not know exactly what kind of control I needed to add until bind time.

Thanks!
 
Fair enough - as long as it works that's the main thing!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
JKelly295,

I am having virtually the same issue. I need to dynamically bind a nested DataList within a Datalist. My nested Datalist is not known until the parent datalist is populated.

I need to bind the nested datalist when I assign the Datasource in ASP page.

On what datalist tag did you code for the OnItemDataBound="MyDataListBoundHandler()" (parent or nested)?

What code did you use within this Sub to bind the nested Datalist?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top