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

I am new with asp.net. And not enjoying it so
so far.

I need to choose an item from the DropDownList
(Data linked with Data Source to SQL Table) and
populate info from same table into a textbox.

Please any help would be appriciated!!
Posted

DataSet dtst_Equals = ObjCommon.GetObject.ExecuteQuery_Select(Connection.ConnectionString, "select Created_By from Tbl_Property_Master where Record_Id='" + Id + "'");
if (dtst_Equals.Tables[0].Rows.Count != 0)
{
drplst_Country.SelectedValue = dtst_get_details.Tables[0].Rows[0["Country"].ToString();
}
 
Share this answer
 
C#
AutoPostBack="True" OnSelectedIndexChanged="droplist1_SelectedIndexChanged"


C#
protected void droplist1_SelectedIndexChanged(object sender, EventArgs e)
   {
       using (SqlConnection con = new SqlConnection(conn))
       {
           string query = "select * from Login where uname='" + droplist1.SelectedValue + "' ";
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           DataSet ds = new DataSet();
           da.Fill(ds);
           if (ds.Tables[0].Rows.Count > 0)
           {
               txtbox1.Text=ds.Tables[0].Rows[0].ItemArray[0].ToString();
           }
       }

   }
 
Share this answer
 
you should write the following code on dropdownlist selectedindexchanged event

VB
dim str as string 
str="select column from tablename where colname=@condition"
dim con as new SqlConnection("Data Source=.;Initial Catalog=master; uid=sa;pwd=12335")
dim cmd as new SqlCommand(str,con)
cmd.CommandType=CommandType.Text
cmd.Paramaters.AddWithValue("@condition",DropDownList1.SelectedValue)
dim adap as new SqlDataAdapter(cmd)

dim dt as new DataTable
adap.fill(dt)
TextBox1.text=dt.Rows(0)(0).ToString()
 
Share this answer
 
v3
Comments
StianSandberg 29-Nov-11 2:13am    
just a comment for Solution 1:
You should NEVER insert strings into a sql-statement like that. Use parameters to prevent sql-injections..

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