Touseef Khan
Touseef Khan

Reputation: 443

How to popluat value form database into combo box using Asp.net

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.

Upvotes: 1

Views: 1335

Answers (1)

santosh singh
santosh singh

Reputation: 28672

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
    }

Upvotes: 1

Related Questions