因为表里的数据太长,我想让datagrid有滚动条 可以来回拖,,

解决方案 »

  1.   

    <div style="overflow:auto">
    <asp:datagrid....
    </div>
      

  2.   

    <div style="width:400px; height:200px;overflow:auto">
    <asp:datagrid....
    </div>
      

  3.   

    “/teacher”应用程序中的服务器错误。
    --------------------------------------------------------------------------------分析器错误 
    说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。 分析器错误信息: 类型“System.Web.UI.WebControls.DataGrid”不具有名为“div”的属性。源错误: 
    行 25:  </Columns>
    行 26:  <PagerStyle PageButtonCount="5" Mode="NumericPages"></PagerStyle>
    行 27:  <div style="overflow:auto">
    行 28:  </asp:datagrid>
    行 29:  </div>
     
      

  4.   

    <%@ Page Language="VB" AutoEventWireup="True" Debug="true"%>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SQLClient" %>
    <script runat="server">
          Dim DBConn as SQLConnection
          Dim DBCommand As SQLDataAdapter
          Sub Page_Load(sender As Object, e As EventArgs) 
      DBConn = New SqlConnection("server=nh;Initial Catalog=pubs;uid=sa;pwd=")
              If Not IsPostBack Then 
                 BindGrid()
              End If
          End Sub      Sub MyDataGrid_Page(sender as Object, e As DataGridPageChangedEventArgs) 
             MyDataGrid.CurrentPageIndex = e.NewPageIndex
             BindGrid()
          End Sub      Sub BindGrid() 
          Dim MyCommand As SQLDataAdapter = new SQLDataAdapter("SELECT * FROM authors", DBConn)
              Dim DS As DataSet = new DataSet()
              MyCommand.Fill(DS,"authors") 
              MyDataGrid.DataSource = DS.Tables("authors").DefaultView
              MyDataGrid.DataBind()
          End Sub
    </script><div>
    <table border="1" cellspacing="0" style="WIDTH:700px;BORDER-COLLAPSE:collapse">
    <tr class="tableHeader" bgcolor="#aaaadd" BorderColor="black">
    <td style="WIDTH:50px">
    NO
    </td>
    <td style="WIDTH:200px">
    au_lname
    </td>
    <td style="WIDTH:200px">
    au_fname
    </td>
    <td style="WIDTH:200px">
    Address
    </td>
    </tr>
    </table>
    </div> <div style=" OVERFLOW: auto; WIDTH: 700px; HEIGHT: 200px">
    <asp:DataGrid id="MyDataGrid" runat="server" 
         SelectedItemStyle-BackColor="#99ccff" 
         PagerStyle-Visible="False" PageSize="10" 
         ItemStyle-CssClass="tableItem" HeaderStyle-
         CssClass="tableHeader" HeaderStyle-BackColor = "#aaaadd" 
         BorderColor="black" AutoGenerateColumns="False" 
         DataKeyField="au_id" ShowHeader="False">
    <Columns>
         <asp:templatecolumn ItemStyle-Width="50px">
         <itemtemplate>
             <%# Container.ItemIndex+1 %>
         </itemtemplate>
         </asp:templatecolumn>
         <asp:boundcolumn ItemStyle-Width="200px" runat="server" DataField="au_lname"/> 
         <asp:boundcolumn ItemStyle-Width="200px" runat="server" DataField="au_fname"/> 
         <asp:boundcolumn ItemStyle-Width="200px" runat="server" DataField="Address"/> 
    </Columns>
    </asp:DataGrid>
    </div>
      

  5.   

    谢谢。。xiahouwen(武眉博<活靶子.NET>) 谢谢nnh(菲一打) 
    能交个朋友吗Q:4071940
      

  6.   

    style里设置绝对位置left:0px;right:0px;top:0px;