aspx_professional thread: Ran into a problem with CH. 7 Pro ASP.NET example
Hi,
In chapter 7 of Wrox's Pro ASP.NET, there is an example using the
OnItemDataBound attribute for a DataList control. When I try to rewrite the
code in C# I ran into a problem.
In the book the first tag of the control is written as such in VB.NET:
<ASP:DataList id="MyDataList" runat="server" RepeatLayout="Table"
OnItemDataBound="CheckTitle">
Below is the one line within the CheckTitle event handler in the book that
I
am having problems with when trying to rewrite it in C#:
Sub CheckTitle(objSender As Object, objArgs As DataListItemEventArgs)
(some code here)
Dim objRowVals As DataRowView = CType(objArgs.Item.DataItem,
DataRowView)
(some code here)
End Sub
I get a "Exception Details: System.InvalidCastException: Exception of type
System.InvalidCastException was thrown." error when I try to do this in C#.
Here is the code I wrote:
void CheckTitle(Object sender, DataListItemEventArgs e)
{
(some code here)
DataRowView objRowVals = (DataRowView)e.Item.DataItem;
(some code here)
}
Any help would be appreciated.