Solved

Dropdown within repeater not updating

Posted on 2016-08-22
5
20 Views
Last Modified: 2016-08-28
Hi,

I have a Dropdownlist inside a repeater that is not updating. I am getting error

An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll

Open in new window


My design is as follows

<asp:DropDownList ID="DropDownList3" runat="server" DataValueField="Line" SelectedValue='<%#DataBinder.Eval(Container.DataItem, "Line")%>' OnDataBinding="getLines"></asp:DropDownList>

Open in new window


Code is

Protected Sub getLines(sender As Object, e As System.EventArgs)
        Dim DropDownList3 As DropDownList = DirectCast(sender, DropDownList)

        Dim cmd As SqlDataAdapter = New SqlDataAdapter("select Line from dbo.production_lines order by Line", cnn)
        Dim ds As DataSet = New DataSet()
        cmd.Fill(ds)

        DropDownList3.DataSource = ds
        DropDownList3.DataTextField = ("Line")
        DropDownList3.DataBind()

        ds.Clear()
        cmd.Dispose()
End Sub

Open in new window

0
Comment
Question by:takwirirar
  • 3
5 Comments
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 41765768
You say there is a repeater in the title but I don't see any repeater defined or code for it in the code behind.
0
 
LVL 8

Expert Comment

by:Prakash Samariya
ID: 41766384
Please check if DataSet fills or not! Error shows "It could not finds the list", and you are trying to assig its' value.

Try below code
<asp:DropDownList ID="DropDownList3" runat="server" OnDataBinding="getLines">/asp:DropDownList>

Open in new window

Back-End
Protected Sub getLines(sender As Object, e As System.EventArgs)
        Dim DrpList3 As DropDownList = DirectCast(sender, DropDownList)

        Dim cmd As SqlDataAdapter = New SqlDataAdapter("select Line from dbo.production_lines order by Line", cnn)
        Dim ds As DataSet = New DataSet()
        cmd.Fill(ds)

        DrpList3.DataSource = ds
        DrpList3.DataBind()

        ds.Clear()
        cmd.Dispose()
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:takwirirar
ID: 41766515
Daniel, the repeater is as follows;

<table style="width: 100%;">

                                        <asp:Repeater ID="Repeater1" runat="server">
                                            <HeaderTemplate>

                                                <tr>
                                                    <td>Line</td>
                                                    <td>Role</td>
                                                    <td>Name</td>
                                                    <td>Level</td>
                                                    <td>Present</td>
                                                </tr>

                                            </HeaderTemplate>

                                            <ItemTemplate>
                                                <tr>
                                                    <td>
                                                        <asp:DropDownList ID="DropDownList3" runat="server" DataValueField="Line" SelectedValue='<%#DataBinder.Eval(Container.DataItem, "Line")%>' OnDataBinding="getLines"></asp:DropDownList>
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="DropDownList4" runat="server" DataValueField="Role" SelectedValue='<%#DataBinder.Eval(Container.DataItem, "Role")%>' OnDataBinding="getRoles"></asp:DropDownList>
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="DropDownList5" runat="server" DataValueField="Name" SelectedValue='<%#DataBinder.Eval(Container.DataItem, "Name")%>' OnDataBinding="getNames"></asp:DropDownList>
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="DropDownList6" runat="server" DataValueField="Level" SelectedValue='<%#DataBinder.Eval(Container.DataItem, "Level")%>' OnDataBinding="getLevels"></asp:DropDownList>
                                                    </td>
                                                    <td>
                                                        <asp:CheckBox ID="CheckBox1" runat="server" />
                                                    </td>
                                                </tr>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </table>

Open in new window

0
 
LVL 1

Accepted Solution

by:
takwirirar earned 0 total points
ID: 41766761
Ok I've sorted it using the following;

<asp:DropDownList ID="DropDownList3" runat="server" DataValueField="Line" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "Line") %>' DataSourceID="ProductionDataSource1" DataTextField="Line"></asp:DropDownList>
                                                        <asp:SqlDataSource ID="ProductionDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:productionConnectionString %>" SelectCommand="SELECT [Line] FROM [production_lines] ORDER BY [Line]"></asp:SqlDataSource>

Open in new window


Everything happens in the repeater now
0
 
LVL 1

Author Closing Comment

by:takwirirar
ID: 41773590
Found a workaround without using code behind
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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