?
Solved

Accessing a link button created in a repeater

Posted on 2007-11-23
4
Medium Priority
?
1,288 Views
Last Modified: 2013-11-26
Hi Everyone, here is the problem:  I have created a repeater in ASP.NET that has header titles which are link buttons.  I am trying to access the onClick property of these link buttons so I can set it to a sub procedure stored in the code behind. The sub procedure will then basically reorder the data created in the repeater (a sort effectively)

I have no idea how to access them as they aren't appearing in the drop down lists provided by VS2005.

Could anyone help me if you know how to do so?

Thanks in advance,
Phil





<asp:Repeater ID="Repeater1" runat="server">
                                                <HeaderTemplate>
                                                    
                                                    <table style="border:solid 1px black">
                                                          <tr style="background-color:Black;color:White;font-weight:bold;text-align:center;">
                                                            <td rowspan="2" valign="top">
                                                                Device
                                                            </td>
                                                            <td rowspan="2" valign="top">
                                                                <asp:LinkButton ForeColor="white" ID="lnkNoJourn" OnClick="<% =sortItems(1)%>" runat="server">Number of Journey's</asp:LinkButton>
                                                            </td>
                                                            <td colspan="3">
                                                                 Journey Times (Secs)
                                                            </td>
                                                             <td rowspan="2" valign="top">
                                                                <asp:LinkButton ForeColor="white" ID="lnkNoOfPickups" OnClick="<% =sortItems(5)%>" runat="server">Number of Pickups</asp:LinkButton>
                                                            </td>
                                                             <td rowspan="2" valign="top">
                                                                <asp:LinkButton ForeColor="white" ID="lnkTotHits" OnClick="<% =sortItems(6)%>" runat="server">Total Hits</asp:LinkButton>
                                                            </td>
                                                          </tr>
                                                          <tr style="background-color:Black;color:White;font-weight:bold;text-align:center;">
                                                            <td><asp:LinkButton ForeColor="white" id="lnkAvg" OnClick="<% =sortItems(2)%>" runat="server">Average</asp:LinkButton></td>
                                                            <td><asp:LinkButton ForeColor="white" id="lnkMin" OnClick="<% =sortItems(3)%>" runat="server">Minimum</asp:LinkButton></td>
                                                            <td><asp:LinkButton ForeColor="white" id="lnkMax" OnClick="<% =sortItems(4)%>" runat="server">Maximum</asp:LinkButton></td>
                                                          </tr>                                             
                                                          
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                          <tr class="row">
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Device").ToString.ToUpper%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Journeys")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Avg")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Min")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Max")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Pickups")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Hits")%></td>
                                                          </tr> 
                                                </ItemTemplate>
                                                <AlternatingItemTemplate>
                                                         <tr class="rowAlt">
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Device").ToString.ToUpper%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Journeys")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Avg")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Min")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Max")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Pickups")%></td>
                                                            <td style="width:14%"><%#DataBinder.Eval(Container.DataItem, "Hits")%></td>
                                                          </tr> 
                                                </AlternatingItemTemplate>
                                                <FooterTemplate>
                                                    </table>
                                                    
                                                </FooterTemplate>
                                            </asp:Repeater>

Open in new window

0
Comment
Question by:Artform04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
John Gates, CISSP earned 1050 total points
ID: 20338937
You have to access the elements programatically:

Here is another example as well:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskreferencingcontrolsinwebformspages.asp


-D-
Dim rpi As RepeaterItem
For Each rpi In Repeater1.Items
 
Dim Telephone As String = CType(rpi.FindControl("txtContactPhone"), TextBox).Text
Dim TelephoneExtension As String = CType(rpi.FindControl("txtContactPhoneExt"), TextBox).Text
Dim EmailAddress As String = CType(rpi.FindControl("txtContactEmail"), TextBox).Text
 
Next
 
'The above could be buttons, dropdown lists text boxes...  Whatever you have in the control.

Open in new window

0
 
LVL 1

Author Comment

by:Artform04
ID: 20338993
ok, but how can i assign the sub procedure i created to be the handler for the linkButton click this way??

Alternatively, is there a way i can run the server code sub from the html in code blocks? I know you can run javascript functions but could i run a server-side function instead???

Phil
0
 
LVL 3

Assisted Solution

by:mvarner2000
mvarner2000 earned 150 total points
ID: 20339387
It seems like you're trying to shoehorn the repeater into a job much better suited for the GridView.  Is there a reason why?
0
 
LVL 1

Author Comment

by:Artform04
ID: 20345439
ye, the headers, I have a mixture of data and obviously you can only have one header per row as opposed to having, for lack of a better example mereged cells.  ie. I have a header called "jourey times" and then min,max and avg.  Its ok, Ive bodged my way through now anyway, bit of header hiding and a custome table at the top.

Thanks guys
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question