How To Split Sql Query Result To Populate A Dropdownlist
The DataSet looks like this: Spec1 Spec2 Spec3 Spec4 Spec5 Spec6 Spec7 Spec8 Spec9
Solution 1:
You'll need to use something like this to parse it out. And you'll need to (probably) use a foreach loop and a second DataSet (or a Dictionary<string, string>) object which you can put the values into and then use to data bind your DropDownList.
EDIT: Without the HTML Agility Pack:
Dictionary<string, string> dict1 = new Dictionary<string, string>();
foreach (DataRow r in my.Tables[0].Rows)
{
foreach (DataColumn c in my.Tables[0].Columns)
{
if (r[c] == DBNull.Value || r[c].ToString().Trim() == "")
continue;
string spec = r[c].ToString();
string href = spec.Substring(spec.IndexOf("href=");
href = href.Trim("\"").Substring(0, spec.IndexOf("\""));
....
dict1.Add(href, val);
}
}
ddl1.DataSource = dict1;
ddl1.DataBind();
You might be able to get an easier solution using the library but I'm not sure how well it handles a lack of a document and only having a single element. But that should demonstrate fairly well.
Post a Comment for "How To Split Sql Query Result To Populate A Dropdownlist"