Thursday, September 4, 2008

Overriding PerformDataBinding on Custom ServerControls

I ran into something cool today.  If you Override PerformDataBinding you have access to the DataSource that populated your ListControl.  In my case, I extended RadioButtonList and connected it to an ObjectDataSource that retrieves a List(Of MyObjects) and in the debugger, there was my list of MyObjects in the dataSource collection!


        Protected Overrides Sub PerformDataBinding(ByVal dataSource As System.Collections.IEnumerable)


        End Sub


I guess this would be a good time to mention that I was able to handle the ArgumentOutOfRangeException that occurs when you bind a RadioButtonList and the ListItem doesn’t exist by Overriding OnDataBinding:


        Protected Overrides Sub OnDataBinding(ByVal e As EventArgs)



            Catch ex As ArgumentOutOfRangeException


            End Try

        End Sub


No comments: