Board index » Web Programming » Casting repeater DataItem
|
webchimp
|
Casting repeater DataItem
Web Programming191
Is it possible to cast the DataItem of the repeater control to a typed datatable? I'm trying to use the following code to do this and it doesn't work. This code always throws an invalid cast exception. private void frameRepeater_ItemCreated(object sender, RepeaterItemEventArgs e) { FramesRow frame = e.Item.DataItem as FramesRow; int frameID = 0; if ( frame != null ) frameID = frame.FrameID; } Now if I try the following code it does work, but I can't use my strongly typed database anymore. private void frameRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if ( e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item ) { DataRowView frame = e.Item.DataItem as DataRowView; int frameID = 0; if ( frame != null ) frameID = (int)frame["FrameID"]; DropDownList frameSize = (DropDownList)e.Item.FindControl("frameSize"); frameSize.DataValueField = "FrameSizeID"; frameSize.DataTextField = "FrameSize"; frameSize.DataSource = ServiceFactory.GetProductManager().GetFrameModelSizesTest( frameID ); frameSize.DataBind(); DropDownList frameColor = (DropDownList)e.Item.FindControl("frameColor"); frameColor.DataValueField = "FrameColorID"; frameColor.DataTextField = "Color"; frameColor.DataSource = ServiceFactory.GetProductManager().GetFrameModelColorsTest( frameID ); frameColor.DataBind(); } } regards, Aaron - |
