Datagrid Paging Cell - ColumnSpan Ignored when AutoGenerateColumns

G

Guest

It appears that in the .NET Framework 2.0, if you create a datagrid, set
AllowPaging="true", and set AutoGenerateColumns="true" the behaviour of the
paging cell is incorrect, the ColumnSpan attribute is not rendered into the
table cell data tag, and the table is invalid, with the paging appearing in
the leftmost column, I have produced an example below.

If you do this, you will get 3 columns. The paging will all appear in a
column that is equivalent to the first column. There will only be one cell
in that row, it will only occupy the leftmost column, and have a grid line to
the right.

Debugging at a point in PreRender reveals that ColumnSpan is set, in this
case, correctly to 3. The way I have worked around this is to add a
PreRender event handler where I add an Attribute to the cell myself (e.g.
Attributes.Add("colspan","3") )

<asp:DataGrid runat="server" ID="dGrid" AutoGenerateColumns="true"
PageSize="1" AllowPaging="true" PagerStyle-HorizontalAlign="center"
OnPreRender="dGrid_PreRender" PagerStyle-Position="TopAndBottom">
</asp:DataGrid>

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("A"));
dt.Columns.Add(new DataColumn("B"));
dt.Columns.Add(new DataColumn("C"));

DataRow dr = dt.NewRow();
dr["A"] = "12222222222222";
dr["B"] = "22222222222222";
dr["C"] = "32222222222222";
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1["A"] = "12222222222222";
dr1["B"] = "22222222222222";
dr1["C"] = "32222222222222";
dt.Rows.Add(dr1);
DataRow dr2 = dt.NewRow();
dr2["A"] = "12222222222222";
dr2["B"] = "22222222222222";
dr2["C"] = "32222222222222";
dt.Rows.Add(dr2);

dGrid.DataSource = dt;
dGrid.DataBind();
}
 

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,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top