GridView Modification

May 22, 2009 at 7:48 PM
Edited May 27, 2009 at 5:11 PM

NOTE: All problems that I have encountered have been fixed.

I made two modifications to the GridViewAdapter.cs file in order to allow me to have cells that can use white-space:nowrap and to let me have the GridView render in a way as to allow the table to be scrollable (so that the paging section can be set to absolute and not look strange on a really wide table). In case anyone else is attempting to do the same thing, here are the changes:

The first change goes in WriteRows, between writer.WriteLine(); and cell.RenderControl(writer);

                        writer.WriteLine();
                        //Put a wrapper span inside each <td>, as long as it is just a standard
                        //text cell
                        if (row.RowType == DataControlRowType.DataRow)
                        {
                            if (!cell.HasControls())
                                cell.Text = "<span class=AspNet-GridView-CellContainer>"
                                    + cell.Text + "</span>";
                        }

                        cell.RenderControl(writer);
                        cell.RenderControl(writer);

The second change requires putting code in two places, right before the <table> tag is rendered:

                    //Used to enable gridview scrolling
                    writer.WriteLine();
                    writer.WriteBeginTag("div");
                    writer.WriteAttribute("class", "AspNet-GridView-TableContainer");
                    writer.Write(HtmlTextWriter.TagRightChar);


                    writer.Indent++;
                    writer.WriteLine();
                    writer.WriteBeginTag("table");
                    writer.WriteAttribute("cellpadding", "0");
                    writer.WriteAttribute("cellspacing", "0");
                    writer.WriteAttribute("summary", Control.ToolTip);

and right after the <table> tag is closed:

                    writer.Indent--;
                    writer.WriteLine();
                    writer.WriteEndTag("table");

                    //Used to enable gridview scrolling
                    writer.Indent--;
                    writer.WriteLine();
                    writer.WriteEndTag("div");

May 26, 2009 at 9:28 PM
Edited May 27, 2009 at 4:12 PM

[Post Removed by Author]