Difficult Sorting Situation in Datagrid

L

Lars Netzel

I have a Datagrid using the Edit/Update mode to alter data in the
datasource.

I needed to have a bit more flexible interface in the editmode with a design
that couldn't work in the columns. So I fixed this by only having ONE
template column (plus the edit button column) and then have html tables in
both the header and the edit items to have complete control over the design.
This works fine.
Now my boss wants Sorting in the column headers... and since therer are only
ONE column I can't use the sorting function of the datagrid...

How do I make these headers of my own to trigger the sort event in the grid
and also send the right argumnents?

best regards
/Lars Netzel
 
T

Tim_Mac

hi Lars,
you could create your own linkbuttons with commandname="Sort" and
commandArgument="ColumnName" in your header column.
here is a sample bindGrid function that takes in a sort (and a filter)
to apply to the datasource.

private void bindGrid(string rowFilter, string sort)
{
int ID = Int32.Parse(this.ddlMeatPlants.SelectedItem.Value);
DataSet ds = null;
try
{
ds = new DB.Producers().SelectByMeatPlant(ID);
}
catch(Exception ex)
{
this.lblResult.Text = ex.Message;
return;
}
this.dv.Table = ds.Tables[0];
this.dv.Sort = sort;
dv.RowFilter = rowFilter;
if(dv.Count > 0)
{
this.DataGrid1.Visible = true;
this.DataGrid1.DataSource = dv;
this.DataGrid1.DataBind();
}
}

in the Page_Load, you can call it with empty strings for the sort and
filter parameters. in the event handler for your sort linkbuttons, you
can pass in the commandArgument as the sort parameter.
i haven't tried this, but i think it should work.
tim
 
G

Guest

Hi Lars,

You can assign SortExpression for the template column, e.g. "specialSort".
Then in DataGrid_SortCommand event

if (e.SortExpression.Equals("specialSort"))
{
// special sorting
}
else
{
// normal sorting
}

HTH

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Difficult datagrid 0
sorting datagrid columns 2
Datagrid Sorting 0
Sorting in dataGrid 2
Webforms Datagrid Sorting/Paging... 2
Sorting in nested datagrid 0
APNSoft DataGrid 3.2 Released! 0
Datagrid sorting 1

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top