Show SelectedItem in Dropdownlist based on DataRow

i try to show the item in drop down list if the datarow returns let's say 2,
the ddl will select 2. but cannot
if (Request.QueryString["SLID"] != null && Request.QueryString["SLItemDelete"] == null)
                DataSet1TableAdapters.SetLineTableAdapter adpt01 = new DataSet1TableAdapters.SetLineTableAdapter();
                DataTable dt = adpt01.GetSetLineData(Convert.ToInt64(Request.QueryString["SLID"]));

                ddlLevelID.SelectedItem.Text = dt.Rows[0]["LevelID"].ToString();
                ddlClassID.SelectedItem.Text = dt.Rows[0]["ClassID"].ToString();
                ddlSubjectID.SelectedItem.Text = dt.Rows[0]["SubjectID"].ToString();
                ddlTopicID.SelectedItem.Text = dt.Rows[0]["TopicID"].ToString();

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

try like  this,
ddlLevelID.SelectedValue= dt.Rows[0]["LevelID"].ToString();
doramail05Author Commented:
had this

'ddlClassID' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
You need to bind the Dropdowns(if you havent).

Make Sure that the DataValueField for 'ddlLevelID' is set to 'LevelID' and do the same for the other ddls.

Also, If the fields are nullable, then you need to add a 'null' value on the Dropdowns (i.e. if Dropdown has values (1,2,3,4) and the item selected has "Null" or empty string, you will get that error.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>> 'ddlClassID' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

This error shows that you are trying to set the value of dropdown which does not exists in the dropdown.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.