Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doogie - 15 Jun 2007 19:21 GMT
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.
Masudur - 16 Jun 2007 08:59 GMT
> 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
[quoted text clipped - 7 lines]
> 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
Doogie - 18 Jun 2007 13:30 GMT
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?
Masudur - 19 Jun 2007 08:19 GMT
> 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
Doogie - 19 Jun 2007 16:20 GMT
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.
Masudur - 20 Jun 2007 11:48 GMT
> Well, the problem has kind of changed.
>
[quoted text clipped - 24 lines]
> 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
Doogie - 20 Jun 2007 13:28 GMT
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!)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.