Click here to Skip to main content
16,018,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

i am binding a dropdown with Database

Country | State | District | City

Dropdown is working fine I want to show state Code in textbox and State_Code in State Table

Question Which States I select in dropdown i want to show the State_Code of that State in Textbox

What I have tried:

<div class="form-group col-md-3">
                              <label for="inputState" class="col-form-label">State</label>
                              <asp:DropDownList ID="State_Select" CssClass="form-control" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="States_Name" DataValueField="States_Id"></asp:DropDownList>

                              <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Retail_Billing %>" SelectCommand="SELECT * FROM [States] WHERE ([Country_Id] = @Country_Id)">
                                  <SelectParameters>
                                      <asp:Parameter DefaultValue="1" Name="Country_Id" Type="Byte" />
                                  </SelectParameters>
                              </asp:SqlDataSource>

                          </div>

                          <div class="form-group col-md-3">
                              <label for="district" class="col-form-label">District</label>
                              <asp:DropDownList ID="District_Select" CssClass="form-control" runat="server" DataSourceID="SqlDataSource2" DataTextField="District_Name" DataValueField="District_Id" AutoPostBack="True"></asp:DropDownList>
                              <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Retail_Billing %>" SelectCommand="SELECT * FROM [District] WHERE ([States_Id] = @States_Id)">
                                  <SelectParameters>
                                      <asp:ControlParameter ControlID="State_Select" DefaultValue="0" Name="States_Id" PropertyName="SelectedValue" Type="Byte" />
                                  </SelectParameters>
                              </asp:SqlDataSource>
                          </div>
                          <div class="form-group col-md-3">
                              <label for="Location" class="col-form-label">Location</label>
                              <asp:DropDownList ID="Location_Drop" CssClass="form-control" runat="server" DataSourceID="SqlDataSource3" DataTextField="Location_Name" DataValueField="Location_Id"></asp:DropDownList>
                              <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:Retail_Billing %>" SelectCommand="SELECT * FROM [Location] WHERE ([District_Id] = @District_Id)">
                                  <SelectParameters>
                                      <asp:ControlParameter ControlID="District_Select" DefaultValue="0" Name="District_Id" PropertyName="SelectedValue" Type="Int32" />
                                  </SelectParameters>
                              </asp:SqlDataSource>
                          </div>


                          <div class="form-group col-md-2">
                              <label for="inputZip" class="col-form-label">Zip</label>
                              <input type="text" class="form-control" placeholder="Zip" id="inputZip">
                          </div>
Posted
Updated 6-Jun-18 12:02pm

1 solution

Handle SelectedIndexChanged event of your State_Select DrodDownList and set AutoPostback to True and then do something like this:

C#
protected void State_Select_SelectedIndexChanged(object sender, EventArgs e)
{
       TextBox1.Text = State_Select.SelectedItem.Text;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900