1, Careless put the field name in DataValueField wrong.
2. Write DataBind () behind Findbyvalue (), the following code is in the correct order:
1Bll. Student Bllstu =NewBLL.
Student (); 2 //set up a data source
3Studdl.datasource =bllstu.getstudentlist ();4 //Set display data field name
5Studdl.datatextfield ="Stuname";
6 //Set Value field name
7Studdl.datavaluefield ="Stuid";
8 //binding
9 Studdl.databind ();Ten //Set the selected value
OneStuDDL.Items.FindByValue (Stuid). Selected =true;
3. The data source did not find the value. That should add a non-null judgment, the code is as follows:
1Bll. Student Bllstu =NewBLL.
Student (); 2 //set up a data source
3Studdl.datasource =bllstu.getstudentlist ();4 //Set display data field name
5Studdl.datatextfield ="Stuname";
6 //Set Value field name
7Studdl.datavaluefield ="Stuid";
8 //binding
9 Studdl.databind ();Ten //Getchecked Values
One ObjectFindvalue=StuDDL.Items.FindByValue (stuid); A if(findvalue!=NULL)
- {
-findvalue.selected =true;
the }
ASP. DropDownList Findbyvalue Object reference not set to an instance of an object workaround