OK, I have an SQL Query that gets data from tables and diplay it. The query is:
using (SqlConnection conn = new SqlConnection(connString))
{
string sqlQuery = "SELECT * FROM tblObiectiv t1 JOIN tblCladire t2 ON t1.OID = t2.OID JOIN tblLocatie t3 ON t2.CID = t3.CID ORDER BY t1.Obiectiv";
using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
{
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
DataList8.DataSource = ds.Tables[0];
DataList8.DataBind();
conn.Close();
}
}
and display with
but the result is displayed like

and I want to be like


Prasad RaveendranPosted Oct 15, 2023, 6:32 PM
Remove the
because you don't need the header row in this format.Within the
, keep the structure as it is, but remove the header labels. This template will be used for each row of data.Now, in your C# code-behind, you will need to handle the logic for grouping the data and dynamically controlling the display of the "Obiectiv" values to match the format you provided. You can use a placeholder to conditionally display the "Obiectiv" value only when it changes.
Here's an example of how you can achieve this:
Make sure to set the
OnItemDataBoundevent of your DataList control to theDataList8_ItemDataBoundmethod in your code-behind.This code checks if the "Obiectiv" value has changed compared to the previous row and controls the visibility of the "Obiectiv" value accordingly. This way, it creates the grouped format you are looking for.
Marius VasilePosted Oct 16, 2023, 4:35 PM
And indeed worked for second grouping by
and
Thanks again
Marius VasilePosted Oct 16, 2023, 4:25 PM
So, I used, as you mentioned
and...it works like a charm. Now I have to work on a second grouping, by Cladire
Thank you Prasad!
Marius VasilePosted Oct 16, 2023, 5:01 AM
Thank you Prasad, I will try it today. If I want to add another category let's say for Cladire, I should have the same approach?