Accessing RepeaterItem.DataItem in nested repeaters

G

Guest

Hello all!

I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if
this is the wrong forum!

Synopsis:
In my webform I have 3 nested repeaters:

rpWeeks
----- rpTime
---------- rpClasses

I am databinding the first repeater in the !IsPostBack event of the page,
and the data is coming from a Typed Dataset. The next repeater is DataBound
on its parent's "ItemDataBound"-event and so on:

private void rpWeeks_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Repeater rpTime = (Repeater)e.Item.FindControl("rpTime");
rpTime.ItemDataBound += new
RepeaterItemEventHandler(rpTime_ItemDataBound);
//And here is the code to bind the rpTime-repeater, although I've left it
out for simplicity
}

private void rpTime_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//Same thing here.. Getting the repeater and binding
}

All this works perfectly!

However, inside the rpClasses-repeater (the last one) I have a CheckBox with
an OnCheckedChanged-event and AutoPostBack=True:

//This event will fire, but RepeaterItem.DataItem is NULL on PostBack !
public void c_CheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
RepeaterItem r = (RepeaterItem)c.Parent;
balletDataset.classnameRow _cnr = (balletDataset.classnameRow)r.DataItem;
//r.DataItem is NULL on each
postback and the application will stop!
Response.Write(_cnr.teacher
+ "<br>");
}

I'm pretty sure that this is a state/event-problem, but what can I do to
solve it? I need to have access to the DataItem of the RepeaterItem because I
have to know what values were selected by the user!

I really hope that someone can help me with this one!

Thanks in advance,

Thomas.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

microsoft.public.dotnet.framework.aspnet

is the NG for asp.net

Now regarding your problem I have never used that construction, I do agree
with you that it should be a state problem, but how to find it and correct
it I frankly have no idea.

A possible workaround would be if you use a hidden html control and set the
ID or PK of the datarow in it, then in the postback event handler you know
which was selected.

It would not be perfect but will certainly solve your problem.

What is happening in my opinion is that the inners repeaters are dynamic
controls, hence they needs to be recreated on each postback, how expensive
this is I have no idea really. but you could give it a try.


cheers,
 
G

Guest

Ignacio,

Thanks for your help!
Now regarding your problem I have never used that construction

Well.. If you've never used this construction before, what construction do
you use then? To me, this is the most "straight-forward" approach I could
think of using nested repeaters, but I may be wrong, and am more than willing
to learn!

And thanks for pointing out the correct newsgroup! I'll use that for any
further problems I run into! ;)

Thanks in advance,

Thomas
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,
Well.. If you've never used this construction before, what construction do
you use then? To me, this is the most "straight-forward" approach I could
think of using nested repeaters, but I may be wrong, and am more than
willing
to learn!

I meant I have never had the need of nesting repeaters, therefore I cannot
tell you (Based on experience) if you need to recreate the nested repeaters
, nevertheless I think you do !.

The hidden approach would solve your problem if all you need to know is a
single value, if the row has a PK in the dataset it should be enough to know
which record was selected.


In general you can post asp.net posts here and most of the time they will be
answered


cheers,
 

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

Top