Binding to a Repeater in Codebehind...a little confusion.

N

nobody

Why doesn't the casting of "e.Item.DataI­tem" as a "DataRow" (or even
a "DataRowView" as in other online examples) work? I would love to get
this type of code to work with my code that uses a Label for building a
URL instead of the RadioButtonList as in the example snippet below. I
know how to implement this with a Label but I end up having to do
something like this:

myLabel.Text = (string) DataBinder.Eval(e.Item.DataItem, "Info");

instead of something much cleaner, logical looking, and desirable (to
me) like this:

myLabel.Text = (string) ((DataRow)e.Item.DataI­tem)["Info"];

Also, the thought of "DataBinder.Eval" just seems to partially negate
moving this to the codebehind.

-

Here is an example snippet from this newsgroup that I found that
doesn't work either...and it give the same "cast" error on casting as
"DataRow".

<asp:repeater id="rptEstimates" runat="server"
ItemDataBound="DataBoundItem>
....


<script runat="server">
void DataBoundItem(Object Sender, RepeaterItemEventArgs e) {


// This event is raised for the header, the footer,
separators,
and items.


// Execute the following logic for Items and Alternating
Items.
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType
==
ListItemType.AlternatingItem) {
RadioButtonList rbl =
(RadioButtonList)e.Item.FindCo­ntrol("rptEstimates");
if ( rbl != null )
{
rbl.SelectedValue =
(string)((DataRow)e.Item.DataI­tem)["BidResponse"];
}
}
}

-

Is there a problem with Framework version maybe?
 
N

nobody

More I look into this the more confusing it gets. I think I am too
close to the subject matter at the moment.
 
N

nobody

More I look into this the more confusing it gets. I think I am too
close to the subject matter at the moment.


I went ahead and created my own custom web control. I could have made
modifications at the dataset level before the bind but with this
situation, it was a better fit to build a new control.

Thanks (for nuttin' ;-)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top