Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Repeater Help

Posted on 2009-05-08
7
Medium Priority
?
320 Views
Last Modified: 2013-11-08
I have created a repeater that displays academic information (degrees, college, etc.).  I want the user to be able to edit the entry (entry = degree).  Right now I'm attempting to use a LinkButton and pass the EntryID as the CommandArguement.  I thought this would work but I'm getting a strange error(Unable to cast object of type 'System.EventArgs' to type 'System.Web.UI.WebControls.CommandEventArgs').

My questions:

1. Is the route I'm taking possible, if so what am I doing wrong?

2. What are your suggestions for using a repeater and passing a parameter?

Thanks.
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="odsDegreeDetails">
                <HeaderTemplate>
                    <table width="80%">
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td style="width: 60%; vertical-align: top">
                            <b>Institution: </b>
                            <%#Container.DataItem("NAME")%>
                        </td>
                        <td style="width: 40%; vertical-align: top">
                            <b>Degree: </b>
                            <%#Container.DataItem("DESCRIPTION")%>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 60%; vertical-align: top">
                            <b>Major: </b>
                            <%#Container.DataItem("MAJOR")%>
                        </td>
                        <td style="width: 40%; vertical-align: top">
                            <b>Grad. Date: </b>
                            <%#Container.DataItem("END_DATE")%>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <b>Honors:</b>
                            <%#Container.DataItem("HONOR")%>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:LinkButton ID="lbEdit" runat="server" CommandArgument='<%#Container.DataItem("DegreesId")%>'  ValidationGroup="Edit" OnClick="lbEdit_Click">Edit</asp:LinkButton>
                            | <a href="delete_degree.aspx?DegreesId=<%#Container.DataItem("DegreesId")%>" onclick="confirmDelete()">
                                Delete</a>
                        </td>
                    </tr>
                </ItemTemplate>
                <SeparatorTemplate>
                    <tr>
                        <td colspan="2">
                            &nbsp;
                        </td>
                    </tr>
                </SeparatorTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>

Open in new window

0
Comment
Question by:mmeisel
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 24335837
Why don't u use the gridview. Editing a gridview is much easier I suppose
0
 
LVL 1

Author Comment

by:mmeisel
ID: 24335862
That's true but I want one record to span multiple rows.  For example (-> indicates the following column)

College 1 -> Degree 1
Major 2 -> Grad Date 1
Edit | Delete

College 2 -> Degree 2
Major 2 -> Grad Date 2
Edit | Delete

etc.

If there is a way to do this with a gridview then fantastic but I thought gridviews could only display one row for each record.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 20

Expert Comment

by:informaniac
ID: 24335934
Try placing gridview inside the repeater and bind the gridviews....

Then it might be possible to edit the gridview inside the repeater....
0
 
LVL 1

Author Comment

by:mmeisel
ID: 24335957
CodeCruisier:

I'm not necessarily trying to edit the information in the repeater.  What I'm trying to accomplish is to pass the CommandArguement to the event handler, in this case lbEdit_Click.  With that CommandArguement I'm going to query the database and populate another form on the page.  My problem is that I cannot read the CommandArguement in the event handler (lbEdit_Click).
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24336010
That is what i meant. What you can do is bind the Tag property of the Edit button to the DegreeID instead of using CommandArguments because repeater does  not use command arguments. Then on serverside, you can access the Tag property of the button easily.
0
 
LVL 1

Accepted Solution

by:
mmeisel earned 0 total points
ID: 24336904
I'm not sure what you mean by the Tag proerty but I got it working.

I placed a LinkButton in my Repeater with a command arguement that is binded to the ID.  Then I created a OnItemCommand event handler for the Repeater.  When I did this I got the ID of the record.

<asp:LinkButton ID="lbEdit" runat="server" CommandArgument='<%#Container.DataItem("Id")%>' CommandName="Edit" ValidationGroup="Edit">Edit</asp:LinkButton>

Reference: http://www.ajaxtutorials.com/ajax-tutorials/using-repeater-to-edit-in-line-with-ajax-in-vb-net/
Protected Sub Repeater1_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles Repeater1.ItemCommand
 
        Label1.Text = (e.CommandArgument.ToString)
 
    End Sub

Open in new window

0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

618 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