ok, i do not know if this is the best solution but it work.
I test this try to replace your statement in values, notice the event OnItemDataBound that makes the trick.
aspx
<table>
<asp:DataList ID="DataList1" runat="server" OnItemDataBound="bounditem">
<ItemTemplate>
<tr><td>
<asp:CheckBox ID="chkCategory" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "OPTION_FNCTN").ToString() %>' /></td><td>
<asp:CheckBoxList ID="ckhSubCategory" runat="server"></asp:CheckBoxList></td></tr>
</ItemTemplate>
</asp:DataList>
</table>
Now in the onload page i just generate the first checkbox which is the category one. notice in the select statement the function DISTINCT.
protected void Page_Load(object sender, EventArgs e)
{
string st = "SELECT distinct OPTION_FNCTN FROM MENUOPTS_T WHERE (OPTION_FNCTN <> '') ORDER BY OPTION_FNCTN";
DataSet ds = new DataSet();
SqlDataAdapter adap = new SqlDataAdapter(st, MyConn);
MyConn.Open();
adap.Fill(ds);
MyConn.Close();
DataList1.DataSource = ds;
DataList1.DataBind();
}
now i create another function while the datalist is bounded this is the function.
protected void bounditem(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string stGet = "SELECT OPTION_DESC FROM MENUOPTS_T WHERE (OPTION_FNCTN = '"+((CheckBox)e.Item.FindControl("chkCategory")).Text+"')";
DataSet dsGet = new DataSet();
SqlDataAdapter adapGet = new SqlDataAdapter(stGet, MyConn);
MyConn.Open();
adapGet.Fill(dsGet);
MyConn.Close();
((CheckBoxList)e.Item.FindControl("chkSubCategory")).DataSource = dsGet;
((CheckBoxList)e.Item.FindControl("chkSubCategory")).DataTextField = "OPTION_DESC";
((CheckBoxList)e.Item.FindControl("chkSubCategory")).DataValueField = "OPTION_DESC";
((CheckBoxList)e.Item.FindControl("chkSubCategory")).DataBind();
}
}
i bet you there are a few ways to do this but, this is the first one that comes to my mind.
Regards