打印本文 打印本文 关闭窗口 关闭窗口
有滚动条、固定Header的ASP.Net DataGrid实现
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3602  更新时间:2009/4/23 10:43:52  文章录入:mintao  责任编辑:mintao
p;                                        </script>";

            Page.RegisterStartupScript("dummyKey" + this.ID, adjustWidthScript);

            //output.Write(adjustWidthScript);

          }

          else

          {

            //Replace the table''''s ID with a new ID.

            //It is tricky that we must only replace the 1st occurence,

            //since the rest occurences can be used for postback scripts for sorting.

            sbRenderedTable.Replace(ID,ID + "_Headers", 0, (temp.IndexOf(ID) + ID.Length));

            Trace.WriteLine(sbRenderedTable.ToString());

            //We only need the headers, stripping the rest contents.

            temp = sbRenderedTable.ToString();

            string tableHeaders = temp.Substring(0, (temp.ToLower()).IndexOf(@"</tr>") + 5);

            Trace.WriteLine(tableHeaders);

            output.Write(tableHeaders);

            output.WriteEndTag("table");

            //Client side script for matching column widths.

            //Can''''t find a way to do this on the server side, since the browser can change widths on the client side.

            string adjustWidthScript = @"

                                                <script language=javascript>

                                                        //debugger;

                                                        var headerTableRow = " + this.ID + @"_Headers.rows[0];

                                                        var originalTableRow = " + this.ID + @".rows[0];

                                                        headerTableRow.height = originalTableRow.offsetHeight;

                                                        for (var i = 0; i < headerTableRow.cells.length; i++) {

                                                                headerTableRow.cells[i].width = originalTableRow.cells[i].offsetWidth;

                                                        }

                                                        " +

              //Also needs to adjust the width of the "<div>" at client side in addition to servier side,

              //since the Table''''s actual width can go beyond the width specified at server side under Edit mode.

              //The server side width manipulation is mainly for design-time appearance.

              this.ID + "_div" + @".style.width = " + this.ID + @".offsetWidth + 20 + ''''px'''';

                                                                " +

              //The following script is for flow-layout. We cannot get the position of the control

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口