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

N

Nathan Baulch

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
 
N

Nathan Baulch

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);
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top