I want to fetch list of students into combo box and on the base of combo box slection I will fetch their related record into another grid. please guide me regarding this task.
1 Answer
You can bind DropDownList as below
DropDownList1.DataSource=GetStudentDataSet();
DropDownList1.DataTextField="StudentName";
DropDownList1.DataValueField="StudentID";
DropDownList1.DataBind();
Put GridView bind code on selected change event of DropDownList as below
void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//Fecth selected student id
int studentId = Convert.ToInt32(DropDownList1.SelectedValue);
//Bind Grdivew
}
3 Comments
Touseef Khan
I have database only and I want to fetch only name from student table in dropdown list,, then after fetching name, on change drop down I wana to fetch particular record related to that selected student
Touseef Khan
int studentname = Convert.ToInt32(ddstd.SelectedValue); it gives FormatException, Input string was not in a correct format.
santosh singh
@Touseef:If you want to fetch Student name then there is no need to convert to int.Simply collect the selected value in string variable like string studentname=DropDownList1.SelectedValue;