Adding Controls To DataGrid Header & Sorting

Discussion in 'ASP .Net Web Controls' started by Neil, Aug 30, 2005.

  1. Neil

    Neil Guest

    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);
    }
    }
     
    Neil, Aug 30, 2005
    #1
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 1, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    589
    Sam Vanderstraeten
    Oct 1, 2003
  2. VSK
    Replies:
    1
    Views:
    701
  3. mlt
    Replies:
    2
    Views:
    1,120
    Jean-Marc Bourguet
    Jan 31, 2009
  4. AlainCD
    Replies:
    0
    Views:
    349
    AlainCD
    Jan 12, 2006
  5. Replies:
    1
    Views:
    447
  6. Henrik
    Replies:
    1
    Views:
    637
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
  7. datagrid having row header and column header

    , Jul 13, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    287
  8. Sudhir

    Sorting by header in a dynamic datagrid

    Sudhir, Aug 22, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    161
    Sudhir
    Aug 22, 2003
Loading...