HREF attribute missing from child DataGrid column headers after render...

Discussion in 'ASP .Net Building Controls' started by Nathan Baulch, Sep 18, 2003.

  1. I am trying to build a WebCustomControl that I can use in multiple web
    applications.

    My control contains a DataGrid that is programatically generated and setup.
    I want the DataGrid to be sortable.
    AllowSort = true and SortExpression is set for all columns.

    However the resulting grid does not have hyper link column headers.
    On closer inspection, the header labels are wraped in <a> tags, but there is
    no href attribute.
    If I programmatically setup a DataGrid in the Page_Load of a page, it works
    fine.

    Here is the code from the Render override of my control:


    DataGrid grid = new DataGrid();
    grid.AllowSorting = true;
    grid.AutoGenerateColumns = false;

    BoundColumn col = new BoundColumn();
    col.DataField = "ONE";
    col.HeaderText = "ONE";
    col.SortExpression = "ONE";
    grid.Columns.Add(col);

    col = new BoundColumn();
    col.DataField = "TWO";
    col.HeaderText = "TWO";
    col.SortExpression = "TWO";
    grid.Columns.Add(col);

    col = new BoundColumn();
    col.DataField = "THREE";
    col.HeaderText = "THREE";
    col.SortExpression = "THREE";
    grid.Columns.Add(col);

    DataTable t = new DataTable();
    t.Columns.Add("ONE");
    t.Columns.Add("TWO");
    t.Columns.Add("THREE");
    t.Rows.Add(new string[] {"1","2","3"});
    t.Rows.Add(new string[] {"4","5","6"});
    t.Rows.Add(new string[] {"7","8","9"});
    grid.DataSource = t;
    grid.DataBind();
    grid.RenderControl(output);


    Why isn't my grid filling the href attributes of the header titles?

    Nathan
     
    Nathan Baulch, Sep 18, 2003
    #1
    1. Advertising

  2. > I am trying to build a WebCustomControl that I can use in multiple web
    > applications.
    >
    > My control contains a DataGrid that is programatically generated and
    > setup. I want the DataGrid to be sortable.
    > AllowSort = true and SortExpression is set for all columns.
    >
    > However the resulting grid does not have hyper link column headers.
    > On closer inspection, the header labels are wraped in <a> tags, but
    > there is no href attribute.
    > If I programmatically setup a DataGrid in the Page_Load of a page, it
    > works fine.



    Solution: Add the grid to the Controls collection of my custom control.

    this.Controls.Add(grid);
     
    Nathan Baulch, Sep 19, 2003
    #2
    1. Advertising

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. Replies:
    2
    Views:
    1,098
    Henry S. Thompson
    Mar 6, 2006
  2. CRON
    Replies:
    24
    Views:
    203,875
    Adrienne Boswell
    Jun 20, 2006
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,208
    David Schwartz
    Dec 9, 2003
  4. Ian
    Replies:
    2
    Views:
    2,113
  5. Bitswapper
    Replies:
    5
    Views:
    184
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page