ASP.NET Forms Help / DropDownList

I created 2 dropdownlists which are tied to SQL DB and then pull down the GridView. But more specifically, is there a way to have 3 custom boxes and then show the Gridview? I would like to have a quick efficient way to do this without problems. I created the first 2 DDLs with autorepeat and didn't work as expected. any suggestions?

    <asp:Label ID="CustomerNumberLabel" runat="server" Text="Customer Number " Width="125px"></asp:Label>
    <asp:DropDownList ID="CustomerNumber" runat="server" AutoPostBack="True" 
        DataSourceID="ADDRDataSource" DataTextField="SACSNO" 
        DataValueField="SACSNO" AppendDataBoundItems="True">
        <asp:ListItem Text="Select a Customer" Value="" Selected="True" />
    </asp:DropDownList><br />
    <asp:SqlDataSource ID="ADDRDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>" 
        SelectCommand="SELECT [SACSNO] FROM [ADDR] WHERE ([SARP#1] = @column1)">
        <SelectParameters>
            <asp:SessionParameter Name="column1" SessionField="userName" Type="Decimal" />
        </SelectParameters>
    </asp:SqlDataSource>
     <asp:Label ID="ShipToNumberLabel" runat="server" Text="Ship-to Location " Width="125px"></asp:Label>   
    <asp:DropDownList ID="ShipToNumber" runat="server" 
        DataSourceID="ADDRShipToNumberDataSource" DataTextField="SASHNM" 
        DataValueField="SASHNM" AutoPostBack="True">
        <asp:ListItem Text="Select Ship-To Location" Value="" Selected="True" />
    </asp:DropDownList>
    <asp:SqlDataSource ID="ADDRShipToNumberDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>" 
        SelectCommand="SELECT [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SACSNO], [SASHST], [SASZIP] FROM [ADDR] WHERE ([SACSNO] = @SACSNO)">
        <SelectParameters>
            <asp:ControlParameter ControlID="CustomerNumber" Name="SACSNO" 
                PropertyName="SelectedValue" Type="Decimal" />
        </SelectParameters>
    </asp:SqlDataSource>
   <br /><br />
    <asp:FormView ID="FormView1" runat="server" 
        DataSourceID="ADDRShippingDataSource" Width="400px">
        <EditItemTemplate>
            SACSNO:
            <asp:TextBox ID="SACSNOTextBox" runat="server" Text='<%# Bind("SACSNO") %>' />
            <br />
            SASHNM:
            <asp:TextBox ID="SASHNMTextBox" runat="server" Text='<%# Bind("SASHNM") %>' />
            <br />
            SASAD1:
            <asp:TextBox ID="SASAD1TextBox" runat="server" Text='<%# Bind("SASAD1") %>' />
            <br />
            SASAD2:
            <asp:TextBox ID="SASAD2TextBox" runat="server" Text='<%# Bind("SASAD2") %>' />
            <br />
            SASCTY:
            <asp:TextBox ID="SASCTYTextBox" runat="server" Text='<%# Bind("SASCTY") %>' />
            <br />
            SASHST:
            <asp:TextBox ID="SASHSTTextBox" runat="server" Text='<%# Bind("SASHST") %>' />
            <br />
            SASZIP:
            <asp:TextBox ID="SASZIPTextBox" runat="server" Text='<%# Bind("SASZIP") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
        <InsertItemTemplate>
            SACSNO:
            <asp:TextBox ID="SACSNOTextBox" runat="server" Text='<%# Bind("SACSNO") %>' />
            <br />
            SASHNM:
            <asp:TextBox ID="SASHNMTextBox" runat="server" Text='<%# Bind("SASHNM") %>' />
            <br />
            SASAD1:
            <asp:TextBox ID="SASAD1TextBox" runat="server" Text='<%# Bind("SASAD1") %>' />
            <br />
            SASAD2:
            <asp:TextBox ID="SASAD2TextBox" runat="server" Text='<%# Bind("SASAD2") %>' />
            <br />
            SASCTY:
            <asp:TextBox ID="SASCTYTextBox" runat="server" Text='<%# Bind("SASCTY") %>' />
            <br />
            SASHST:
            <asp:TextBox ID="SASHSTTextBox" runat="server" Text='<%# Bind("SASHST") %>' />
            <br />
            SASZIP:
            <asp:TextBox ID="SASZIPTextBox" runat="server" Text='<%# Bind("SASZIP") %>' />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                CommandName="Insert" Text="Insert" />
            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </InsertItemTemplate>
        <ItemTemplate>
            Customer Detail<br />
            <br />
            <table class="style1" width="35px">
                <tr>
                    <td class="style2" align="center" >
                        Address Line 1</td>
                    <td class="style3" align="center" >
                        <asp:Label ID="SASAD1Label" runat="server" Text='<%# Bind("SASAD1") %>' />
                    </td>
                </tr>
                <tr>
                    <td class="style2" align="center" >
                        Address Line 2</td>
                    <td class="style3" align="center" >
                        <asp:Label ID="SASAD2Label" runat="server" Text='<%# Bind("SASAD2") %>' />
                    </td>
                </tr>
                <tr>
                    <td class="style2" align="center">
                        City</td>
                    <td class="style3" align="center" >
                        <asp:Label ID="SASCTYLabel" runat="server" Text='<%# Bind("SASCTY") %>' />
                    </td>
                </tr>
                <tr>
                    <td align="center" class="style2">
                        State</td>
                    <td class="style3" align="center" >
                        <asp:Label ID="SASHSTLabel" runat="server" Text='<%# Bind("SASHST") %>' />
                    </td>
                </tr>
                <tr>
                    <td align="center" class="style2">
                        Zip</td>
                    <td class="style3" align="center" >
                        <asp:Label ID="SASZIPLabel" runat="server" Text='<%# Bind("SASZIP") %>' />
                    </td>
                </tr>
            </table>
            <br />
        </ItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="ADDRShippingDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>" 
        SelectCommand="SELECT [SACSNO], [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SASHST], [SASZIP] FROM [ADDR] WHERE ([SASHNM] = @SASHNM)">
        <SelectParameters>
            <asp:ControlParameter ControlID="ShipToNumber" Name="SASHNM" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

      

0


source to share


1 answer


You can disable AutoPostBack for all DropDownLists and add a Lookup Button to the Lookup Button_Click with something like this:

ADDRShippingDataSource.SelectParameters.Clear()

If ShipToNumber.SelectedValue <> "" Then
    ADDRShippingDataSource.SelectParameters.Add("SASHNM", ShipToNumber.SelectedValue)
End If

If CustomerNumber.SelectedValue <> "" Then
    ADDRShippingDataSource.SelectParameters.Add("SACSNO", CustomerNumber.SelectedValue)
End If

ADDRShippingDataSource.DataBind()

      



Your select command should be updated to include additional criteria in your DataSource:

SELECT [SACSNO], [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SASHST], [SASZIP] FROM [ADDR] WHERE (@SASHNM IS NULL OR [SASHNM] = @SASHNM) OR (@SACSNO IS NULL OR [SACSNO] = @SACSNO)

      

0


source







All Articles