protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string Con = ConfigurationManager.ConnectionStrings["dbConn"].ToString(); SqlConnection cnn = new SqlConnection(Con); SqlCommand cmd = new SqlCommand("select * from tbl_Sample", cnn); SqlDataAdapter ada = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); ada.Fill(ds); DropDownList1.DataSource = ds; DropDownList1.DataValueField = "id"; DropDownList1.DataTextField = "numbers"; DropDownList1.DataBind(); } }
create table tbl_Sample2 ( id int identity(1,1) not null, numbers varchar(30) primary key(id) )
insert into tbl_Sample values('ONE') insert into tbl_Sample values('TWO') insert into tbl_Sample values('THREE')
Join Hands Change lives Thanks & Regards Straight Edge Society
this.ComboBox1.DataSource = YourDataSet; // Set Data Source here this.ComboBox1.DisplayMember ="Emp_Name"; // Column_Name. this.ComboBox1.ValueMember = "Emp_Code"; // Column_Name
ComboboxItem item = new ComboboxItem(); item.Text = "Item text1"; item.Value = 12; comboBox1.Items.Add(item);
string sText = comboBox1.SelectedItem; string sValue = comboBox1.SelectedValue;
Login to post response