I am trying to create a nested DataList with multiple subcategories listed
under each primary category. Unfortunately, I end up with a bunch of
multiple SubCategory values after iterating through the loop. My code is as
follows:
//*************** *************** *************** *************** ****
for(int i=0;i<=cat.Coun t-1;i++)
{
ds = new DataSet();
ds = catDS;
adapter = new SqlDataAdapter( "SELECT DISTINCT Category1 as CategoryName,
Category2 as CategoryName, Category3 as CategoryName, Category4 as
CategoryName, SubCategory1 AS SubCategory, SubCategory2 AS SubCategory,
SubCategory3 AS SubCategory, SubCategory4 AS SubCategory FROM Products_Table
WHERE Category1 = '"+cat[i].ToString()+"' OR Category2 =
'"+cat[i].ToString()+"' OR Category3 = '"+cat[i].ToString()+"' OR Category4
= '"+cat[i].ToString()+"' ",cnn);
adapter.Fill(ds ,"SubCategories ");
}
ds.Relations.Cl ear();
ds.Relations.Ad d("SubRelation" ,ds.Tables["Categories "].Columns["CategoryNa me
"], ds.Tables["SubCategor ies"].Columns["CategoryNa me"]);
dl1.DataSource = ds;
dl1.DataBind();
//*************** *************** *************** *************** **************
********
The resulting data looks like this:
Category1
SubCategory1, SubCategory1, SubCategory2, SubCategory3,
SubCategory3, SubCategory4
Category2
SubCategory1, SubCategory2, SubCategory3, SubCategory3
SubCategory4, SubCategory4, SubCategory4
etc. etc. ...
I'm not sure how I can fix this issue, any suggestions?
under each primary category. Unfortunately, I end up with a bunch of
multiple SubCategory values after iterating through the loop. My code is as
follows:
//*************** *************** *************** *************** ****
for(int i=0;i<=cat.Coun t-1;i++)
{
ds = new DataSet();
ds = catDS;
adapter = new SqlDataAdapter( "SELECT DISTINCT Category1 as CategoryName,
Category2 as CategoryName, Category3 as CategoryName, Category4 as
CategoryName, SubCategory1 AS SubCategory, SubCategory2 AS SubCategory,
SubCategory3 AS SubCategory, SubCategory4 AS SubCategory FROM Products_Table
WHERE Category1 = '"+cat[i].ToString()+"' OR Category2 =
'"+cat[i].ToString()+"' OR Category3 = '"+cat[i].ToString()+"' OR Category4
= '"+cat[i].ToString()+"' ",cnn);
adapter.Fill(ds ,"SubCategories ");
}
ds.Relations.Cl ear();
ds.Relations.Ad d("SubRelation" ,ds.Tables["Categories "].Columns["CategoryNa me
"], ds.Tables["SubCategor ies"].Columns["CategoryNa me"]);
dl1.DataSource = ds;
dl1.DataBind();
//*************** *************** *************** *************** **************
********
The resulting data looks like this:
Category1
SubCategory1, SubCategory1, SubCategory2, SubCategory3,
SubCategory3, SubCategory4
Category2
SubCategory1, SubCategory2, SubCategory3, SubCategory3
SubCategory4, SubCategory4, SubCategory4
etc. etc. ...
I'm not sure how I can fix this issue, any suggestions?