We help IT Professionals succeed at work.

asp.net I have just added some code with a skin template. I would like to know how to prevent it from excuting twice.

westdh
westdh used Ask the Experts™
on
the dropdownlist gets filled properly when the page is displayed, but it is filled twice (the list is duplicated). How can I prevent from occuring within the code i have added.
<div>
         <table align="center" border="0"  cellpadding="2">
                <tr>
                    <td width="320">
                     <asp:DropDownList ID="ddlExt3" DataSourceID="dsPopulateExt3" AutoPostBack="true"
                            DataValueField="MyData" runat="server" Width="110px" Font-Size="11px" AppendDataBoundItems="true">
                            <asp:ListItem Text="All" Value="%"></asp:ListItem>
                     </asp:DropDownList>     
                    </td>
                </tr>
                </table>
                <asp:SqlDataSource ID="dsPopulateExt3" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>"
                SelectCommand="SELECT DISTINCT  [State] + ' ' + [City] + ' ' + [Ext2] + ' ' + [Ext3]   AS MyData
  FROM [trip4usdnn].[trip4usdnn].[Netism_MapExtreme_Locations] where state = 'OR' or state = 'WA'"></asp:SqlDataSource>
      </div>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
remove AutoPostBack="true"

Commented:
Sorry renove AppendDataBoundItems="true"

Commented:
remove AppendDataBoundItems="true"
Dim dr As ListItem = New ListItem("", "0")
        Dim ss = address.GetStates
        With Me.ddlStates
            .Items.Clear()
            .Items.Add(dr)
            .DataSource = ss
            .DataBind()
        End With

Open in new window

Author

Commented:
How do I merge these two together?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body style="background-color: #8f8fb1">
    <form id="form1" runat="server">
             <div>
                <table align="center" border="0"  cellpadding="2">
                <tr>
                    <td width="320">&nbsp;
                     <asp:DropDownList ID="ddlExt3" DataSourceID="dsPopulateExt3" AutoPostBack="true"
                            DataValueField="MyData" runat="server" Width="110px" Font-Size="11px" AppendDataBoundItems="true">
                            <asp:ListItem Text="All" Value="%"></asp:ListItem>
                     </asp:DropDownList>     
                    </td>
                </tr>
                </table>
                <asp:SqlDataSource ID="dsPopulateExt3" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>"
                SelectCommand="SELECT DISTINCT  [State] + ' ' + [City] + ' ' + [Ext2] + ' ' + [Ext3]   AS MyData
  FROM [trip4usdnn].[trip4usdnn].[Netism_MapExtreme_Locations] where state = 'OR' or state = 'WA'"></asp:SqlDataSource>
              </div>
    </form>
</body>
</html>



Dim dr As ListItem = New ListItem("", "0")
        Dim ss = address.GetStates
        With Me.ddlStates
            .Items.Clear()
            .Items.Add(dr)
            .DataSource = ss
            .DataBind()
        End With 
Toggle Highlighting

Open in new window

Commented:

Class state
        'SELECT DISTINCT  [State] + ' ' + [City] + ' ' + [Ext2] + ' ' + [Ext3]   AS MyData
        Public Property StateName As String
        Public Property City As String
        Public Property Ext2 As String
        Public Property Ext3 As String
        Public Property MyData As String = String.Format("{0} {1} {2} {3}", StateName, City, Ext2, Ext3)
        Public Property State As String
    End Class
    Private Function GetStates() As IList(Of State)

    End Function
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            Dim dr As ListItem = New ListItem("%", "0")
            Dim ss = GetStates
            With Me.ddlExt3
                .Items.Clear()
                .Items.Add(dr)
                .DataSource = ss
                .DataBind()
            End With
        End If
    End Sub

Open in new window

Author

Commented:
Thanks you for your support