Set a Value into ComboBox using DataTable

T.saravanan
Posted by T.saravanan under C# category on | Points: 40 | Views : 15145
Hi,
Here I am give a Code for how to set a value into comboBox using DataTable.

DataTable dtData=new DataTable();
ComboBox1.DisplayMember="Name"; // Its for user View.
ComboBox1.ValueMember="ID"; // its for get particular Id for that Name.
DataRow drRow=dtData.NewRow();
drRow["Name"]="--Select--";
drRow["ID"]=0;
dtData.Rows.InsertAt(drRow,0); //Set into First Row
ComboBox.DataSource=dtData.Copy();
ComboBox.SelectedIndex=0; // Show a First Value

//Get a Value from ComboBox
string sId=ComboBox.SelectedValue.ToString();

I hope it useful.
Thanks
T.Saravanan :)

Comments or Responses

Login to post response