Oct
06
2006
Grouping repeater - the codebehind
Posted by admin under
Controls
This is part 6of this tutorial on how to create a expandable/collapsible grouping repeater control with ASP.NET. So, please start by reading part 1.
What happens page is loaded first time or the button Run is clicked?
We will get into detail later, but lets look at the click handler:
protected void Button1_Click(object sender, EventArgs e)
{
m_oGroupingHelper = new GroupingHelper();
m_oGroupingHelper.SetImageSwapper("images/minus.gif", "images/plus.gif");
//Run report...
//1. create SQL
string sSQL = "select * from orders ";
if (DropDownList1.SelectedValue != "None")
sSQL += "order by " + DropDownList1.SelectedValue;
//Run the regular query - sort on group value!!!
DataTable dt = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset("Server=(local);Database=northwind;User ID=sa;Password=stefan;Trusted_Connection=False",
CommandType.Text, sSQL).Tables[0];
dt = m_oGroupingHelper.SetupGroupedTable(dt, DropDownList1.SelectedValue);
rptOrder.DataSource = dt;
rptOrder.DataBind();
//After databind - we have the JS ready...
if (ClientScript.IsClientScriptBlockRegistered("poorman_" + rptOrder.ID) == false)
{
ClientScript.RegisterClientScriptBlock(typeof(Page),
"poorman_" + rptOrder.ID, m_oGroupingHelper.GetJS());
}
}
We create some sort of GroupingHelper - it's a class which will help create the javascripts needed and also abstracts some of the datasource modifications needed.
We run the query - sorted by the grouping column. We now send the resulting datatable into the groupingHelpers.SetupGroupedTable - which will modify the datatable and create extra rows for each header row ( with Row["poorman_type"] set to "groupheader" - remember?).
Last of all we generate the needed Javascript - and the helper class does all that for us as well.
READ NEXT PART