Can i add the database item to drop down list
-
Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net
-
Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net
sandeep sangshetty wrote:
i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database.
did you complete the first level, that City and Country read from Database and bind it to dropdown list ? if yes then do one thing, on selectetd index changed of City name ,call the same function that you have used for load country name first time. just change the query as ,
Select Country from mydB where City='"+ ddlCity.text + "'
hope this will help you. if you have any doubts you can ask me .cheers, Abhijit
-
Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net
sandeep sangshetty wrote:
Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list).
Yes.DropDownList has SelectedValue property, ddl.SelectedValue="Ahmedabad"; // if value is cityname OR ddl.SelectedValue="YourCityID"; //if value if cityID
please don't forget to vote on the post that helped you.
-
Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net
Have you filled the Country DDl first in Update Form?? Then do following: 1. Run a query and get CountryID or CountryName What ever you want from Database for that perticular user. (Lets Take ID in this case) 2. write this code after getting CountryID:
int intCountryID = .....; // ID u got from database
for(int i=0;i<(ddlCountry.Length);i++)
{
if(ddlCountry[i].Value == intCountryID)
ddlCountry.SelectedIndex = i;
}3. Write this code into ddlCountry's SelectedIndexChanged property:
.
.
.//write code to get cities for that country selected from database
. here and load all cities into ddlCity
.
int intCityID = .....; // ID u got from database
for(int j=0;j<ddlcity.length);j++)>
{
if(ddlCity[i].Value == intCityID )
ddlCity.SelectedIndex = j;
}4. Bingo!!! Problem Solved Got it?????????
Anand Desai Developer Atharva Infotech
-
Have you filled the Country DDl first in Update Form?? Then do following: 1. Run a query and get CountryID or CountryName What ever you want from Database for that perticular user. (Lets Take ID in this case) 2. write this code after getting CountryID:
int intCountryID = .....; // ID u got from database
for(int i=0;i<(ddlCountry.Length);i++)
{
if(ddlCountry[i].Value == intCountryID)
ddlCountry.SelectedIndex = i;
}3. Write this code into ddlCountry's SelectedIndexChanged property:
.
.
.//write code to get cities for that country selected from database
. here and load all cities into ddlCity
.
int intCityID = .....; // ID u got from database
for(int j=0;j<ddlcity.length);j++)>
{
if(ddlCity[i].Value == intCityID )
ddlCity.SelectedIndex = j;
}4. Bingo!!! Problem Solved Got it?????????
Anand Desai Developer Atharva Infotech
Anand Desai wrote:
int intCountryID = .....; // ID u got from database for(int i=0;i<(ddlCountry.Length);i++) { if(ddlCountry[i].Value == intCountryID) ddlCountry.SelectedIndex = i; }
Just one line can do this.
ddlCountry.SelectedValue=intCountryID.ToString();
please don't forget to vote on the post that helped you.
-
Anand Desai wrote:
int intCountryID = .....; // ID u got from database for(int i=0;i<(ddlCountry.Length);i++) { if(ddlCountry[i].Value == intCountryID) ddlCountry.SelectedIndex = i; }
Just one line can do this.
ddlCountry.SelectedValue=intCountryID.ToString();
please don't forget to vote on the post that helped you.
That detailed code was to make Sandeep understand the basic procedure. Even I can imagine and understand what u wrote. but we have to explain all in simple language to that man. do u think Sandeep will digest as easily your line compare to my code?????????? Just wanted to teach how to think to our Juniors!!!
Anand Desai Developer Atharva Infotech
-
Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net
Here you will get lot of replies to your question but i bet you are not going to learn anything as you are not showing any efforts to tackle the problem. It seems that you are in learning phase for which you should always take help from google, there are n number of articles for developers which are in initial stage. Please try to learn first then if you stuck with any issue (atleast put some efforts )then ask question here that's the meaning of any forum. This is how you are going to learn :)
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog
-
Here you will get lot of replies to your question but i bet you are not going to learn anything as you are not showing any efforts to tackle the problem. It seems that you are in learning phase for which you should always take help from google, there are n number of articles for developers which are in initial stage. Please try to learn first then if you stuck with any issue (atleast put some efforts )then ask question here that's the meaning of any forum. This is how you are going to learn :)
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog
Very true.I m completely agree with u.
Anand Desai Developer Atharva Infotech
-
Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net
I think your update form's city dropdownlist and country dropdownlist contains list of city and country.And you want the particular city and country to come as selected. For that by using the select query you take the value to the form.You assign that to a string variable.For example the city value is assigned to strCity and country to strCountry.If the city's dropdownlist is DropDownList1 and country's is DropDownList2. Then you can use the following code if (DropDownList1.Items[0].Text == strCity) { DropDownList1.SelectedItem.Text =strCity; } else { DropDownList1.Items.Insert(0, strCity); } if (DropDownList2.Items[0].Text == strCountry) { DropDownList2.SelectedItem.Text =strCountry; } else { DropDownList2.Items.Insert(0, strCountry); } Hope This Code Help You