Populating a SelectList from a DataTable

前端 未结 8 1097
说谎
说谎 2020-12-18 11:12

I ran a query and returned a datatable,

myDataAdapter.Fill(myDataTable);

Now what is the best way to load the row values \"Value\" and \"Te

8条回答
  •  猫巷女王i
    2020-12-18 11:18

    Assuming your DataTable has 2 columns (text and value), you have to

    1. Set the DropDownList's DataSource to the table
    2. Set the DataTextField to the text column name
    3. Set the DataValueField to the value column name
    4. Call the Databind method
    

提交回复
热议问题