Accessign System.Web.UI.WebControls.Repeater in code

  • Thread starter Thread starter Doogie
  • Start date Start date
D

Doogie

I have a Repeater control in an app I'm updating. I need to write
code (event method) when a user clicks on one of the columns in the
control. But there is no method like "Repeater_OnClick" or something
like that. Is there a way to get access to this control with an event
method of some kind?

If not, (and here's where my inexperience in web development will show
through), is there another server side grid type control that I could
switch to? I would prefer not to do this as there is a lot of other
code (in javascript, etc) that is tied to this control but if I have
no choice I'm not sure which is the best to use.
 
I have a Repeater control in an app I'm updating. I need to write
code (event method) when a user clicks on one of the columns in the
control. But there is no method like "Repeater_OnClick" or something
like that. Is there a way to get access to this control with an event
method of some kind?

If not, (and here's where my inexperience in web development will show
through), is there another server side grid type control that I could
switch to? I would prefer not to do this as there is a lot of other
code (in javascript, etc) that is tied to this control but if I have
no choice I'm not sure which is the best to use.

hi...

I am not sure of exactly what problem you are referring ...
But if the problem is catching repeater's click event in server
side...
then try itemCommand event of reapeater... and use e.commandname
e.commandsource etc... to solve your problem

Thanks
Masudur
 
Hi Masudur,

I put some code in the itemCommand event for my repeater, put a
breakpoint on that code, clicked on the grid when I ran the app and
nothing happened. What action causes the itemCommand event to be
executed?
 
Hi Masudur,

I put some code in the itemCommand event for my repeater, put a
breakpoint on that code, clicked on the grid when I ran the app and
nothing happened. What action causes the itemCommand event to be
executed?

I am not sure what is going on there...
here how it should go...

<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="SqlDataSource1" OnItemCommand="Repeater1_ItemCommand1">

you put some kind of button or link button .... in itemTemplate or
AlternetingItemTemplete
for example

<ItemTemplate>
<div style="background-color:#cccccc">
<asp:Button ID="btnSelect" Text="Select"
runat="server" CommandName="Select" />
<asp:Label ID="lblName" runat="server" Text=<%#
DataBinder.Eval(Container.DataItem, "Name") %>></asp:Label>
</div>
</ItemTemplate>

as you can see in commandName property of the button i put "Select" As
the command name after that in codebehind file

protected void Repeater1_ItemCommand1(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandName == "Select")
{
//do some code...
}
}

i think i didn't understand what the actual problem is ...
can you be a little bit more descriptive.

Thanks
Masudur
http://munnacs.110mb.com
 
Well, the problem has kind of changed.

Here's an example of what my repeater looks like in html (this is a
partial example for space sake):

<asp:repeater ID="RptTrip" Runat="server" EnableViewState="false">
<ItemTemplate>
<trip_detail_info trip_detail_id ='<%#
Container.DataItem("trip_detail_id")%>'
leg_start_dt = '<%#
Container.DataItem("leg_start_dt")%>' />
</ItemTemplate>
</asp:repeater>

This grid is tied to an xsl document. I would like to set this up so
that I can write a method in VB.NET to access the data in this
control. At this point, I don't need a Repeater control event
anymore, I have a button that I've created - outside of the control -
that will have code behind it to do the work I need.

But I need to know what the data is inside the control. The Repeater
control appears to have no properties/methods, etc of any kind that
will show me what data is inside of it as far as I can tell. So I
can't figure out how to "read my data".

I am thinking that somehow I need to read the xsl but am not sure
there either. At this point, I am not sure what the best approach is
to accomplish this.
 
Well, the problem has kind of changed.

Here's an example of what my repeater looks like in html (this is a
partial example for space sake):

<asp:repeater ID="RptTrip" Runat="server" EnableViewState="false">
<ItemTemplate>
<trip_detail_info trip_detail_id ='<%#
Container.DataItem("trip_detail_id")%>'
leg_start_dt = '<%#
Container.DataItem("leg_start_dt")%>' />
</ItemTemplate>
</asp:repeater>

This grid is tied to an xsl document. I would like to set this up so
that I can write a method in VB.NET to access the data in this
control. At this point, I don't need a Repeater control event
anymore, I have a button that I've created - outside of the control -
that will have code behind it to do the work I need.

But I need to know what the data is inside the control. The Repeater
control appears to have no properties/methods, etc of any kind that
will show me what data is inside of it as far as I can tell. So I
can't figure out how to "read my data".

I am thinking that somehow I need to read the xsl but am not sure
there either. At this point, I am not sure what the best approach is
to accomplish this.

hi...
First can you please make sure that your View state persists... by
enableViewState = true...

foreach(RepeaterItem item in Repeater1.Items)
{
if (item.ItemType == ListItemType.AlternatingItem ||
item.ItemType == ListItemType.Item)
{
Label lbl = (Label)item.FindControl("lblName");
if (lbl != null)
{
string Name = lbl.Text.Trim();
}
}
}

Thanks

Masudur
www.kaz.com.bd
http://munnacs.110mb.com
 
Hi Masudur,
I found a way around my issue. It wasn't exactly what I planned on
doing, I stored the data I needed to access from the repeater grid
inside a hidden control and used that to do what I need. Since I
won't ever be using much data at any given time, this seems to work
well (and gets me around a problem that has been taking days to figure
out!)
 
Back
Top