ASP.NET DataList Databinding
Original Post: http://morewally.com/cs/blogs/wallym/archive/2006/07/20/191.aspx
I have recently been writing a new feature for an ASP.NET 1.1
application. In it, I have a datalist which I bind data to. My
datalist is defined with a rather simple header, item, and footer
templates. When I was capturing the OnitemDataBound event and
processing the databinding of each individual row, I was getting this
really weird error. The issue is that the Header (and I assume the
Footer) bindings are also within the OnItemDataBound event. As a
result, it is necessary to trap and look for what the binding type is.
An example is below. This example will catch .Item and
.AlternatingItem. Some of the other ListItemTypes are:
- EditItem.
- Header.
- Footer.
- Pager.
- Separator.
- SelectedItem.
- Separator.
If you are trying to do some databinding with a DataList in .NET 1.1, I hope that this was helpful.
Public Sub dlStaff_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
If ((e.Item.ItemType = ListItemType.Item) OrElse (e.Item.ItemType = ListItemType.AlternatingItem)) Then
'Do something here
End If
End Sub