Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dropdown within repeater not updating

Posted on 2016-08-22
5
Medium Priority
?
26 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
[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
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 10

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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 …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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