I have a problem populating a dropdownlist with data from a dataset. Here is the code:
string strConnection="user id=logger;password=logger;";
strConnection+="database=MVS;server=4647117000N26";
SqlConnection objSqlConnection = new SqlConnection(strConnection);
objSqlConnection.Open();
DataSet objDataSet = new DataSet();
string strOrderDetails = "SELECT DISTINCT [job_name] FROM [mvs_jobs]";
SqlCommand objOrdDetailCommand = new SqlCommand(strOrderDetails,objSqlConnection);
SqlDataAdapter objODAdapter = new SqlDataAdapter(objOrdDetailCommand);
objODAdapter.Fill(objDataSet);
DropDownList1.DataSource = objDataSet;
DropDownList1.DataBind();
objSqlConnection.Close();
I am not really sure what the problem is, the dropdownbox is populated with "System.Data.DataRowView"...!?!
anyone who can help?
kind regards
Henrik...maybe you need to set the datamember property for the drop down list...
Try this:
string strConnection="user id=logger;password=logger;";
strConnection+="database=MVS;server=4647117000N26";
SqlConnection objSqlConnection = new SqlConnection(strConnection);
objSqlConnection.Open();
DataSet objDataSet = new DataSet();
string strOrderDetails = "SELECT DISTINCT [job_name] FROM [mvs_jobs]";
SqlCommand objOrdDetailCommand = new SqlCommand(strOrderDetails,objSqlConnection);
SqlDataAdapter objODAdapter = new SqlDataAdapter(objOrdDetailCommand);
objODAdapter.Fill(objDataSet);
DropDownList1.DataSource = objDataSet;
DropDownList1.DataTextField = "job_name"
DropDownList1.DataBind();
objSqlConnection.Close();
Thanks, it worked! Now all I have to do is to parse that variable to a new aspx page as parameter and build a crystal report based on the value... piece of cake, eh :)
kind regards
Henrik
Sweden
if you say so.....(piece of cake)......(smile).
Now it is done, I added a reportviewer webcontrol to a new pagepage and used the parameters from the previous page as parameters to the report, then I linked that with a report I have made in Crystal Reports 9. And it WORKS!!!! (on my localhost). I am still having troubles running it in our test-server. I thnk some Crystal dll files haven't been properly registered or even distributed. Crystal Reports works in a funny way, it follows its own standards. And I had to bring out my reference bible on C# in order to understand just how to use that reportviewer control.
Now comes the tricky part, to make the report portal dynamic with logins, profiles, possibility to add new reports to profiles etc etc etc..........the list can be as long as your imagination goes :)
kind regards
Henrik
I might add here as it's the asp.net forum that it is highly advisable to use a datareader to populate in a webform. It's faster than a dataadapter.
I use datareader for any web work. The dataset used with a dataadapter is only of any real use in windows based application.
Hmm, IC. Well I am still learning ASP.NET and I use the same code as I use in my C# desktop programs. Perhaps you can show a small example? I use MS SQL server.
kind regards
Henrik
Saturday, March 24, 2012
Populate dropdownlist...
Labels:
asp,
codestring,
dataset,
dropdownlist,
idloggerpasswordlogger,
net,
populate,
populating,
strconnection,
user
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment