1

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
  • what do you have already? code? structure of database tables? some ORM? Commented May 7, 2011 at 13:30

1 Answer 1

1

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
    }
Sign up to request clarification or add additional context in comments.

3 Comments

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
int studentname = Convert.ToInt32(ddstd.SelectedValue); it gives FormatException, Input string was not in a correct format.
@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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.