Anybody know how I can populate a dropdownlist using an output param from SQL?
I have:
...
SqlParameter parameterScores = new SqlParameter("@dotnet.itags.org.Scores", SqlDbType.NVarChar, 100);
parameterScores.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterScores);...
...Users userInfo = new Users();
userInfo.Name = (string)parameterName.Value;
userInfo.Scores = (string)parameterScores.Value;return userInfo;
...
...Name.Text = userInfo.Name;
scores.DataSource = userInfo.Scores;
Any help will be greatly apprecieated.
Thanksif 'Users' is a collection you should be able to use your code, be sure to call the scores.DataBind() method...
otherwise, just put the values in a collection (Dictionary, HashTable, etc) or array and access them.
// Method 1.) Binding...
Hashtable myHash = new Hashtable();
myHash.Add("key1", "Ohio"); // Add these when you get the info from the db
myHash.Add("key2", "Vermont"); // Add these when you get the info from the db
dd.DataSource = myHash;
dd.DataTextField = "Value";
dd.DataValueField = "Key";
dd.DataBind();
// Method 2.)
Just simply add the values when you've got them.
ie:
dd.Items.Add("Ohio"); // Add these when you get the info from the db
dd.Items.FindByText("Ohio").Value = "myKeyValue";
Let me know if you have problems...
0 comments:
Post a Comment