hi!
i am using listbox control to bind the one column data. in sql server i take one table like Emp. in that table "Ename" column data is bind into the listbox control. i done in web application. but in windows applications how to write the code to do this. i write code in web applications like.
listbox1.datasource = ds.tables[0];
listbox1.datatextfield = "Ename";
listbox1.databind();
Please give a code to do this.
thanks.
Loading
VasanthPosted Apr 9, 2010, 2:23 AM
Here just we cast from checkedlistbox to listbox .
//Create temp datatable for bind values
DataTable dtTemp = new DataTable(); DataRow dr;
//create schema
dtTemp.Columns.Add("Eid"); dtTemp.Columns.Add("Ename");
//Add temp datas
dr = dtTemp.NewRow(); dr["Eid"] = "1"; dr["Ename"] = "CAAA"; dtTemp.Rows.Add(dr);
dr = dtTemp.NewRow(); dr["Eid"] = "2"; dr["Ename"] = "CBBB"; dtTemp.Rows.Add(dr);
dr = dtTemp.NewRow(); dr["Eid"] = "3"; dr["Ename"] = "CCCC"; dtTemp.Rows.Add(dr);
dr = dtTemp.NewRow(); dr["Eid"] = "4"; dr["Ename"] = "CDDD"; dtTemp.Rows.Add(dr);
dr = dtTemp.NewRow(); dr["Eid"] = "5"; dr["Ename"] = "CEEE"; dtTemp.Rows.Add(dr);
//Just u cast here
(checkedListBox1 as ListBox).DataSource = dtTemp;
(checkedListBox1 as ListBox).DisplayMember = "Ename";
(checkedListBox1 as ListBox).ValueMember = "Eid";
Please mark as answer , if it helps you.
ajay rajuPosted Apr 8, 2010, 7:32 AM
hi! Vasanth Thank u for giving Replay. if u don't mine also give acode for doing data bind in CheckedListBox in Windows Application.
i am waiting for ur replay.
Thank u.
VasanthPosted Apr 6, 2010, 3:00 AM
listbox1.DataSource = ds.Tables["
listbox1.DisplayMember = "Ename";
Please mark as answer , if it helps you.