Here the dropdownlist is used to select a row through the ID column.
The selected row's cell data will be displayed on textboxes.
The database table I have used is as shown: (Table name: details1).
Bind the Dropdownlist with the ID column of the table either by using the fallowing code or by the smart task menu >> ConfigureDataSource wizard.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con1 = new SqlConnection("your connectionstring");
con1.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select id from details1", con1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
Dropdownlist1.DataSource = ds1;
Dropdownlist1.DataTextField = "id";
Dropdownlist1.DataBind();
con1.Close();
}
{
if (!IsPostBack)
{
SqlConnection con1 = new SqlConnection("your connectionstring");
con1.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select id from details1", con1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
Dropdownlist1.DataSource = ds1;
Dropdownlist1.DataTextField = "id";
Dropdownlist1.DataBind();
con1.Close();
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
SqlConnection con1 = new SqlConnection("your connectionstring");
con1.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select name,designation,place from details1 where id=@id", con1);
{
SqlConnection con1 = new SqlConnection("your connectionstring");
con1.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select name,designation,place from details1 where id=@id", con1);
da1.SelectCommand.Parameters.AddWithValue("@id", DropDownList1.Text);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
con1.Close();
DataRow row1 = dt1.Rows[0];
txtname.Text = row1["name"].ToString();
txtdsgn.Text = row1["designation"].ToString();
txtplace.Text = row1["place"].ToString();
}
DataTable dt1 = new DataTable();
da1.Fill(dt1);
con1.Close();
DataRow row1 = dt1.Rows[0];
txtname.Text = row1["name"].ToString();
txtdsgn.Text = row1["designation"].ToString();
txtplace.Text = row1["place"].ToString();
}
This comment has been removed by a blog administrator.
ReplyDelete