Adding Controls To DataGrid Header & Sorting

N

Neil

Hi,

I'm building a custom version of the DataGrid control, I want this control
to sort and display an indication to the user of the sort direction. I've
seen examples of adding a label control to the header item using the
OnItemCreated event. I've followed the example
http://www.msdn.microsoft.com/msdnmag/issues/01/10/cutting/default.aspx

but now I have a problem. After the first sort the sort expression in the
sort event is reported as the column to the right of the actual one I
clicked. I can see from hovering over the column heading that the postback
is reporting column 1 as ctl1in the dopostback code, this should be ctl0 and
seems to be causing an issue.

This only happens when I add a label control to the header cell using the
following code.

for(int i=0; i < Columns.Count; i++)
{
if(sortExpr == Columns.SortExpression)
{
TableCell cell = e.Item.Cells;
Label sortedLbl = new Label();
sortedLbl.Font.Name = "Webdings";
sortedLbl.Font.Size = FontUnit.XSmall;
sortedLbl.Text = symbolText;
cell.Controls.Add(sortedLbl);
}
}
 

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

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top