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") )
<aspataGrid runat="server" ID="dGrid" AutoGenerateColumns="true"
PageSize="1" AllowPaging="true" PagerStyle-HorizontalAlign="center"
OnPreRender="dGrid_PreRender" PagerStyle-Position="TopAndBottom">
</aspataGrid>
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();
}
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") )
<aspataGrid runat="server" ID="dGrid" AutoGenerateColumns="true"
PageSize="1" AllowPaging="true" PagerStyle-HorizontalAlign="center"
OnPreRender="dGrid_PreRender" PagerStyle-Position="TopAndBottom">
</aspataGrid>
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();
}