Databinding in dropdownlist from database in asp.net with C#.NET
I gave four columns in a table in the next page i take one dropdownlist and three textboxes if select name in dropdownlist the other should be come in textboxes
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Krishna GaradRank #191 · 12.8K reputationPosted Jun 21, 2011, 2:43 AM EDT
For your requirment first bind the Dropdownlist with values while page is loading and next in dropdown selected index changed event write the code to selected value and get the values for other textboxes.
belly hits4 reputationPosted Jul 18, 2011, 9:50 PM EDT
Here is a little help for you, may be it work.
Creating an editable GridView whose data comes from a SqlDataSource is amazingly easy. To start, the GridView's SqlDataSource must contain an UpdateCommand with appropriate parameters. Creating such a SqlDataSource is as simple as checking the Generate Insert, Update, and Delete Statements from the dialog box(Recall that this dialog box is accessed through the second step of the SqlDataSource wizard, by clicking the Advanced button.)
You are doing an exciting practice, let me know what you get out of it.
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 19, 2011, 5:43 AM EDT
First Enable AutoPostBack of DropDownList to true after that in Selected_index changed event
using System.Data.SqlClient;
SqlConnection con=new SqlConnection("connection string");
SqlCommand com;
string str;
void Page_Load()
{
if(!IsPostBack)
{
con.Open();
str = "select * from student";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
dropdownlist.Items.Add(reader["name"]);
}
reader.Close();
con.Close();
}
}
void DropDownList1_SelectedIndexChanged()
{
con.Open();
str = "select * from student where name='" + DropDownList1.SelectedValue + "'";
com = new SqlCommand(str, con);
SqlDataReader reader=com.ExecuteReader();
if( reader.Read())
{
textBox1.Text = reader["id"].ToString();
textBox2.Text = reader["age"].ToString();
textBox3.Text = reader["marks"].ToString();
textBox4.Text = reader["address"].ToString();
}
con.Close();
reader.Close();
}
}
If this help you mark it as Answer.