How to change the dropdownlist's value from database on selection of 1 st dropdownlist

Hi Friends,

I have 2 dropdownlist. 1 for country and 1 for state. When i will select any coutary according to that all state related to that countary shoud change in dropdownlist. I have to fatch both dropdownlist's value from sqlserver database.

And i also don't know how to make relationship to get all value in aspx page. so please also tell me what should i made in database means primary foreign key concept.

I will be very thankful if you can send me code for that. 

 

0
Nisha
1/31/2009 3:31:49 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
962 Views

Similar Articles

[PageSpeed] 20

There will be 2 tables in the database, Country with country_id as primary key. Another table State with state_id as primary key and country_id as foreign key. Then on the load event, fill the first dropdown list with post back check. Also set the Autopostback property of the first dropdownlist to True. On the SelectedIdnexChanged event of the first dropdownlist get the selected value of the first dropdownlist and fill the second one using this value.

 Hope this will help.

 


Please Mark AS Answer if it helped.
Regards
ADEEL EHSAN
0
adeelehsan
1/31/2009 3:47:45 PM
Reply:

Similar Artilces:

Default value for Dropdownlist that get's it's value from Database.
Hi, I am using an Object Data Souce to retrieve the value of a Dropdownlist from a table on MS SQL server 2005. I want to make a default value appear on the Dropdownlist intially, should i enter the default value into the database table or is that a better way of doing it? Any suggestions will be very much appreciated. E  No need for database just set sekected value after databingind protected void Page_Load(object sender, EventArgs e) { DataBind(); ListItem defaultItem = new ListItem("Select a Person", "-1"); th...

change dropdownlist's selected value on textbox change
Hi there, I have one dropdownlist and textbox in template column of gridview. Now whenever grideview is in edit mode user can change textbox and dropdown value. Now I want to set dropdownlist's selected index to 0 when user enter any value in text box using javascript. i m new to javascript. Is there any idea to implement this? Check this out.   var ddl = document.getElementById('<%#dropdownlistname.ClientID%>'); ddl.selectedIndex = 0;    Thanks,santosh_maharajaPlease mark as answer if you got expected solution. this wayprotected void gvw_RowDataBoun...

Dropdownlist's Value Updates Another Dropdownlist's list
Hi, I'm looking for the best way to update a dropdownlist's list based on a value choosen from another dropdownlist on the page. A common example of this is there are two DDLs.  One for state and one for county.  The county DDL is left blank until a state is choosen.  Once a state is choosen then the county dropdownlist is filled. Now here is part of my dilemma.  I'm entered other data on the form, so if I postback I need some way of knowing that the postback is just for the purpose of filling the secont dropdownlist.  In addition everytime that first DDL is change...

dropdownlist's selected index value is not printing the selected value
Here iS my code .Aspx Page <asp:DropDownList ID="ddlkeyword" runat="server" Width="204px" DataTextField="Form" DataValueField="Form" OnSelectedIndexChanged="ddlkeyword_SelectedIndexChanged" >   </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="Submit" Width="110px" OnClick="Button1_Click" /> my aspx.cs protected void Page_Load(object sender, EventArgs e) { fillddlkeyword(); }protected void Page_Init(object sender, EventArgs e) { ...

Custom paging and DataGrid's PageSize value change through dropdownlist control
I'm implementing custom paging for a datagrid through an asp.net dropdownlist control that postback the new pagesize. It looks like: protected void ddlRecordsPerPage_OnSelectedIndexChanged(object sender, EventArgs e) {             this.dgLocations.PageSize = Int32.Parse(this.ddlRecordsPerPage.SelectedItem.Value); } But upon the page reloading, the old pagesize is what loads on not the new one.  Only when I do a postback again does the new pagesize take effect. I know many would recommend that I do something like BindData() ...

dropdownlist
i have created a dropdown list that is populated from a sqlserver datasource. i have a separate sql command which uses the dropdownlist.selected value as a parameter and returns the command value to a label.  it mostly works fine but with one problem. when the page loads, the label value is null, because it doesn't seem to treat the dropdownlist default value as a selected value. when i use the dropdownlist to select a value, this is fine and the label begins to display the expected value. is there anyway I can make the default value when the page is loaded act like a manual...

Dropdownlist's choice changes other dropdownlist in datagrid
I have a datagrid that contains several dropdownlists. On edit, I would like to have dropdownlistA's choice, based on a selected choice, affect other controls in that datagrid. I am having problems accessing those controls with the OnSelectedIndexChanged command. Does anyone have any suggestions? Thanks What is the problem. Post your codeBug [MCSD] Well that is the problem I don't know how to code it. Below is code with psuedo code on the html side I have a datagrid and for one of my controls and I am using OnSelectedIndexChanged="ddlPDType_Change" : <asp:DropDownLi...

Getting DropDownlist's DataTextValue Selected Value Given the SelectedValue and/or Selected Item
In the vb.net codebehind, I need to extract something from the Text (displayed) value of dropdownlist's selected item and I have  the SelectedValuand and SelectedItem in hand. How can I do this?  FindControl? Item? row?   Thanks. Well, its easier than you might think. SelectedItem has a "text" property. Thats the selected text right there :)  If you need the Text of the selection, then you have to use the SelectedItem.Text property.  If you want the value (not the displayed text) the you can directly use the SelectedValue. dim sText as String = dropdown...

Dropdownlist on website
When I access an application written in asp.net 2.0 on my pc (uses XP) and on a laptop (using Vista), I can type into the dropdownlist to search for a record.  But other pc's (using XP) do not allow the user type to do a search.  Only the first letter of the word or the drop down are available to do a search.   Does anyone know why it would work with some pc's but not on others? I think this behaviour is in IE 7, check to see what versions of IE the PC's have that done work.-------------------------------------------------------...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

DropDownList selected value determines value of second DropDownList
I have a quick question that I'm sure has been addressed before, but I can't seem to find a solution. I have two drop down list fields: startTime and endTime coded as such: <asp:DropDownList id="startTime" runat="server"> <asp:ListItem Value="00:00">12:00 A.M.</asp:ListItem> <asp:ListItem Value="00:30">12:30 A.M.</asp:ListItem> <asp:ListItem Value="01:00">1:00 A.M.</asp:ListItem> <asp:ListItem Value="...

Coding DropDownList's Selected Value and ArgumentOutOfRangeException
I have a SQLDataSource that feeds a table of account names and numbers to a DropDownList which in turn feeds the account number to a ListView to display all related orders.  The dropdownlist has an autopostback to update the ListView - and that works fine. I then have Page_Load checking to see if there is a QuerySting value that can be parsed into an Int32 and passed to the DropDownList as the SelectedValue.  If the account number exists in the query that the SqlDataSource provides, then it properly selects the correct row.  But as a test, I changed the QueryString value to a...

dropdownlist
Hi folks, I am a novice - simple. I have done my homework by reading articles online and as a last resort coming over here. The Problem I am not able to retrieve the Text and Value selected from the dropdownList (dynamically populated) user control. The application is instead is always returning me the first item in the dropdownlist (even if the user selected something else). Here are some related pieces of code. AddNewSubCategory.aspx Contains this line of dropdownlist code. (pretty standard) This drop down list is being dynamically populated by the Sub BindCategoryList(...

Dropdownlist box's visibility, when "yes" of another dropdownlist box is selected
There is a dropdown Listbox. The items are, "Yes" and "No". Let's say, it is ddl1. If "yes" of ddl1 is selected, ddl2 will be visible at run time which was made invisible from design time. This should be written in Javascript using Web Form Controls (Not HTML controls). I am working in ASP .Net and VB language. Please do it fast. Thanks in advance. Sneha   Dear Sneha,  Try this.  <form id="form1" runat="server"> <div> <asp:ListBox ID="ddl1" runat="server" AutoPostBack="T...

Web resources about - How to change the dropdownlist's value from database on selection of 1 st dropdownlist - asp.net.presentation-controls

Resources last updated: 11/21/2015 8:03:35 PM