Casting repeater DataItem

A

Aaron Prohaska

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top