to : goody9807() ----------------------------- 谢谢你,孟老大那里我去了,但是对齐的方法在动态添加的时候实现起来有偏差!所以来求大家帮忙!
the easy way is to fake it with a fixed-width table above the grid:<table width=400> <tr> <td width=200>hello</td><td width=200>world</td> </tr> </table> <div style="width:400;overflow-y:auto; height:400"> <!--your datagrid is here and set the right width for your TableCell--> </div>
try the following, if you don't like to create multiple controls, you can always write a custom control to encapsulate them: <%@ Page Language="C#" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.SqlClient" %> <script runat="server"> void Page_Load(object o, EventArgs e) { if (!IsPostBack) { SqlDataAdapter da = new SqlDataAdapter("select * from authors", "server=localhost;database=pubs;uid=sa;pwd=;"); DataTable dt = new DataTable(); da.Fill(dt); DataGrid1.DataSource = dt.DefaultView; DataGrid1.DataBind(); } }</script> <html> <head> </head> <body> <form id="form1" runat="server"> <table width=600 cellspacing="0"> <tr><td width=200 align="center">Employee ID</td><td width=200 align="center">Last Name</td><td width=200 align="center">First Name</td></tr> </table> <div style="overflow-y:auto;height:200"> <asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="false" ShowHeader=false ItemStyle-Width="600"> <Columns> <asp:BoundColumn HeaderText="Employee ID" DataField="au_id" ItemStyle-Width="200" /> <asp:BoundColumn HeaderText="Last Name" DataField="au_lname" ItemStyle-Width="200" /> <asp:BoundColumn HeaderText="First Name" DataField="au_fname" ItemStyle-Width="200" /> </Columns> </asp:DataGrid> </div> </form></body> </html>
-----------------------------------------------------------------
这中方法用了,但是动态的列对齐有困难,尤其是有滚动条后,我准备把功能实现后封成web控件,所以这样做解决不了问题!
-------------------------------------------------------
你好,能说一下在哪加,怎么加吗?
-----------------------------
谢谢你,孟老大那里我去了,但是对齐的方法在动态添加的时候实现起来有偏差!所以来求大家帮忙!
<tr>
<td width=200>hello</td><td width=200>world</td>
</tr>
</table>
<div style="width:400;overflow-y:auto; height:400">
<!--your datagrid is here and set the right width for your TableCell-->
</div>
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server"> void Page_Load(object o, EventArgs e)
{
if (!IsPostBack)
{
SqlDataAdapter da = new SqlDataAdapter("select * from authors",
"server=localhost;database=pubs;uid=sa;pwd=;"); DataTable dt = new DataTable();
da.Fill(dt); DataGrid1.DataSource = dt.DefaultView;
DataGrid1.DataBind();
}
}</script>
<html>
<head>
</head>
<body>
<form id="form1" runat="server">
<table width=600 cellspacing="0">
<tr><td width=200 align="center">Employee ID</td><td width=200 align="center">Last Name</td><td width=200 align="center">First Name</td></tr>
</table>
<div style="overflow-y:auto;height:200">
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="false" ShowHeader=false ItemStyle-Width="600">
<Columns>
<asp:BoundColumn HeaderText="Employee ID" DataField="au_id" ItemStyle-Width="200" />
<asp:BoundColumn HeaderText="Last Name" DataField="au_lname" ItemStyle-Width="200" />
<asp:BoundColumn HeaderText="First Name" DataField="au_fname" ItemStyle-Width="200" />
</Columns>
</asp:DataGrid>
</div>
</form></body>
</html>
<asp:BoundColumn HeaderText="Last Name" DataField="au_lname" ItemStyle-Width="200" />
<asp:BoundColumn HeaderText="First Name" DataField="au_fname" ItemStyle-Width="200" />
---------------------------------------------------
这是固定宽度的,但还是谢谢你!
第一个只显示标题
第二个使用模板(不要标题,只显示内容)。给第二个DataGrid加<marquee></marquee>标记就可以了
第一个只显示标题
第二个使用模板(不要标题,只显示内容)。
---------------------------------------------
这个方法用过了,出现的问题是:第一个不显示内容的情况下,同一列的宽度和下面的相同数据源的grid的列宽并不一样的!