By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

Accessing RepeaterItem.DataItem in nested repeaters

P: n/a
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.
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"DonRex" <Do****@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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.

Nov 16 '05 #2

P: n/a
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

"Ignacio Machin ( .NET/ C# MVP )" wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"DonRex" <Do****@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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.


Nov 16 '05 #3

P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.