Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey, i have two dropdownlist and one textbox in which

dpl.1> name of city
dpl.2> name of city
txtbox.1>kilometer to get


As it is connected to sql database , so i wish that the data(name of city) in dropdownlist directly select from database in both dropdownlist and quick answer the kms in txtbox.


Is there any genius , who can solve these problem....!
Posted
Comments
Not clear. Can you please elaborate simply ?
veenusethi 25-Aug-12 0:28am    
do you want bind dropdownlist with sql?
if yes simply click on arrow of dropdownlist in right hand and select your database and table from where city name will come.
and on textbox you can use like
textbox.text=dropdownlist1.selecteditem.text on any event
kinjal b patel 25-Aug-12 1:03am    
thanks buddy.....
AmitGajjar 25-Aug-12 3:02am    
this is really very easy question. you just need to learn ADO.NET asking for code is not the right way of learning anything. i'm sorry if you think i'm rude.
Brandon Caruana 25-Aug-12 16:20pm    
I agree with @amitgajjar. Have you tried google at all to find an answer?

cmd.commondtext = "Select kilometer From CityMast Where City1=drop1 and city2=drop2"
txetbox.text=cme.executesaclar().tostring();
 
Share this answer
 
Comments
kinjal b patel 25-Aug-12 0:49am    
thanq........!
You also Try this:
make Both Dropdown Autopost Back Proprty = True..

on Page Load Event :
SQL
if (!IsPostBack)
{
         FillDropDownList();
         FillDropDownList1();
}


The Function is :

 private void FillDropDownList()
    {
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("select city from tablename ",con);
        myda.Fill(ds);
        drop_city.DataSource = ds;
        drop_city.DataValueField = "city";
        drop_city.DataBind();
    }


private void FillDropDownList1()
    {
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("select city from tablename ",con);
        myda.Fill(ds);
        drop_city1.DataSource = ds;
        drop_city1.DataValueField = "city";
        drop_city1.DataBind();
    }


Double Click on drop_city1 Drop down
string str="Select km from tablename where city ='"+drop_city.SelectedItem.Value+"' and city1='"+drop_city1.SelectedItem.Value+"'";
        SqlDataAdapter ad = new SqlDataAdapter(str,connection object);
        DataSet ds = new DataSet();
        ad.Fill(ds);

        if (ds.Tables[0].Rows.Count != 0)
        {
            Textbox1.Text = ds.Tables[0].Rows[0][0].ToString();
        }



if any query, please post it....
 
Share this answer
 
use dataset for fetch value(nameofCity,km, etc...) and then use fill combobox like that:

cmb_city.Items.Add(dataset.Tables[0].Rows[i]["column_name"]);

:)happy to help


--TK--
 
Share this answer
 
Use a single function for binding both drop down lists.


C#
if (!IsPostBack)
{
         FillDropDownList();
} 
 
 private void FillDropDownList()
    {
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("select city from tablename ",con);
        myda.Fill(ds);
        drop_city.DataSource = ds;
        drop_city.DataValueField = "city";
        drop_city.DataBind();
        drop_city1.DataSource = ds;
        drop_city1.DataValueField = "city";
        drop_city1.DataBind();
    }
 
Share this answer
 
 
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