Excellent, Thank you Sri, I am now another step closer.
My output now shows all the fields like this...
My Counter: 1
GenreID: 1
GenreName: All Music
My Counter: 2
GenreID: 2
GenreName: All Commercial
My Counter: 3
GenreID: 3
GenreName: All House
My Counter: 4
GenreID: 4
GenreName: All Hard Dance
My Counter: 5
GenreID: 5
GenreName: All Alternative Dance
My Counter: 6
GenreID: 6
GenreName: All Techno
My Counter: 7
GenreID: 7
GenreName: All Drum and Bass
My Counter: 8
GenreID: 8
GenreName: All Urban
My Counter: 9
GenreID: 9
GenreName: All Alternative Electronic
My Counter: 10
GenreID: 10
GenreName: All Retro
My Counter: 11
GenreID: 11
GenreName: All Rock
My Counter: 12
GenreID: 12
GenreName: Commercial Pop
My Counter: 13
GenreID: 13
GenreName: Commercial Dance
My Counter: 14
GenreID: 14
GenreName: Club Classics
My Counter: 15
GenreID: 15
GenreName: Funky House
...and so on (there are 52 records)...
I think that with the query working correctly, I should be able to populate my TreeView correctly, but im not quite sure how, I have modified my code so that it now looks like this...
protected void Page_Load(object sender, EventArgs e)
{
XmlDataSource1.Data = GetXmlData(); //populate XmlDataSource1 with the XML data
}
private void GetXmlData()
{
string strSQL = "select " +
"1 as tag, " +
"null as parent, " +
"c.GenreID as [Category!1!Id], " +
"c.GenreName as [Category!1!Name], " +
"null as [SubCategory!2!Id], " +
"null as [SubCategory!2!Name] " +
"from MusicGenres c " +
"where isnull ( c.ParentID , '' ) = '' " +
"union all " +
"select " +
"2, " +
"1, " +
"c1.GenreID, " +
"c1.GenreName, " +
"c2.GenreID, " +
"c2.GenreName " +
"from MusicGenres c1, MusicGenres c2 " +
"where c2.ParentID = c1.GenreID " +
"order by [Category!1!Id] , [SubCategory!2!Id] " +
"for xml explicit";
SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString());
SqlCommand objCommand = new SqlCommand(strSQL, objConn);
objConn.Open();
//return ???? //return the query as a XML datsource?
}
My first question is, will I be able to acheive this. If so, can someone help me get the code working correctly?
My first problem is that i know "private void GetXmlData()" is the wrong opening line for the method, but im not sure what to use, and secondly, how do I return the objCommand correctly so that XMLDataSource1.Data is populated correctly?
[ For reference, i am trying to follow Lakshmi's artical on Binding XML Data to TreeView with checked state of checkboxes (http://lakshmik.blogspot.com/2006/04/aspnet-binding-xml-data-to-treeview.html) ]