I have to display values into text box while selecting drop down list. I have use data set to get values from db. The code is given below. Give me a proper solution. Thank you.
Code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet1TableAdapters.TextBoxTableTableAdapter tx;
tx = new DataSet1TableAdapters.TextBoxTableTableAdapter();
DataTable dt = new DataTable();
dt = tx.GetstudData(int.Parse(DropDownList1.SelectedValue));
foreach (DataRow row in dt.Rows)
{
TextBox1.Text = (row["FirstName"]); // error shown here
TextBox2.Text = (row["SecondName"]); // error shown here
}
}
The dt contains First Name and Last Name values. While selecting student ID the appropriate value shoud be shown in text box1 and textbox 2.
Sql query:
SELECT FirstName, SecondName FROM TextBoxTable WHERE (Id = @Id)
Source:
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
Data base: