fill combobox with items from database [Resolved]

Posted by Jopito under ASP.NET on 12/3/2013 | Points: 10 | Views : 8469 | Status : [Member] | Replies : 9
hi,have got a combobox where i need to fetch the values have entered in my database and display them in my combobox,i tried little code here but cannot figure it out

The code cant populate the combobox with items,.Here is the method

public IList<Employees>GetSourceOfFunds(string sourcefunds)
{
IList<Employees>funds=db.Employees.Where(x=>x.SourceOfFunds==sourcefunds).ToList();
return funds;

}
here is my code on page load to fetech the items
var data = Listemployees.GetSourceOfFunds(sourcefunds);
foreach (Transaction item in data)
{
sourceOfFundscombobox.Items.Add(new RadComboBoxItem(item.SourceOfFunds));
}

Mark as answer if satisfied


Responses

Posted by: Bandi on: 12/3/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
http://www.telerik.com/help/silverlight/radcombobox-populating-with-data-binding-adonet.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 12/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://www.telerik.com/community/forums/aspnet-ajax/combobox/problem-populating-comboboxes-from-sql-database-after-requiredfield-validation.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
http://stackoverflow.com/questions/6261075/how-to-bind-the-radcombobox-at-runtime-in-asp-net
http://www.telerik.com/help/aspnet-ajax/combobox-data-binding-datatable-set-view.html
http://www.telerik.com/community/forums/aspnet-ajax/grid/bind-selectedvalue-after-populating-dropdownlist.aspx
http://www.telerik.com/help/aspnet-ajax/dropdownlist-databinding-datatable.html

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kmandapalli on: 12/3/2013 [Member] Silver | Points: 25

Up
0
Down
Hi,

Go through the following code:

private void fnGetConnectedToDatabase()
{
//Connection string
string conStr="Provider=Microsoft.Jet.OLEDB.4.0;" +
" Data Source=..\\..\\studentDB.mdb";
try
{
//Instantiate OleDbConnection and open
//the connection to the database
myConn = new OleDbConnection(conStr);
myConn.Open();
}
catch(OleDbException ex) {
//get the error message if connection failed
MessageBox.Show("Error in connection ..."+ex.Message);
}
string sqlStr ="SELECT * FROM studentTable;";
//Instantiate a DataAdapter by passing the sqlStr and myConn.
//now data is in raw form
dAdapter = new OleDbDataAdapter(sqlStr,myConn);
//Instantiate a DataSet
dset = new DataSet();
//Gets a collection that provides the master mapping
// between a source table and a DataTable
dAdapter.TableMappings.Add("Table", "studentTable");
//A data adapter object utilizes the Fill method
//to populate a DataSet or a DataTable object with
//data retrieved by a SELECT command.
dAdapter.Fill(dset);
//When binding a DataSet, .NET automatically uses the corresponding
//DataViewManager provided through the DataSet.DefaultViewManager property
this.dviewmanager=dset.DefaultViewManager;
this.comboBox1.DataSource=this.dviewmanager;
//display "studentTable.StudentID" in the ComboBox
this.comboBox1.DisplayMember="studentTable.StudentID";
//DataBinding for the TextBox controls
this.textBox1.DataBindings.Add("Text",
this.dviewmanager,"studentTable.StudentID");
this.textBox2.DataBindings.Add("Text",
this.dviewmanager, "studentTable.StudentSubject");
this.textBox3.DataBindings.Add("Text",
this.dviewmanager, "studentTable.StudentName");
// Close the connection to the database.
this.myConn.Close();
}

Mark as answer if satisfied....

Regards,
Shree M.

Kavya Shree Mandapalli

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 12/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down

refer http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/linqdatasource/defaultcs.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samirbhogayta on: 12/4/2013 [Member] Starter | Points: 25

Up
0
Down
hi.. try this function it's very useful

//To fill the dropdownlist
public void dataset(DropDownList ddl,string str)
{
string constr;
constr = "ConnectionString";
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter dap = new SqlDataAdapter(str, con);
con.Open();
DataSet ds = new DataSet();
dap.Fill(ds);
ddl.Items.Add("Select Option");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if(!string.IsNullOrEmpty(ds.Tables[0].Rows[i].ItemArray[0].ToString()))
{
ddl.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
con.Close();
}

SAMIR
Sr. Software Engineer

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jopito on: 12/4/2013 [Member] Starter | Points: 25

Up
0
Down
Its returning null yet have got data in the table
Yeah,av used that solution above

Mark as answer if satisfied

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 12/4/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
See the below link:-

http://stackoverflow.com/questions/12494634/fill-combobox-from-database

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 12/4/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://www.sourcecodester.com/tutorials/visual-basic-net/5799/filling-combobox-data-stored-mysql-database-visual-basicnet.html

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response