2

所以我现有的结构是

<table>
<tr>
    <th>header</th>
</tr>
<tr>
    <td>cotent</td>
</tr>
</table>

DataGrid 正在添加一堆我不想在那里的东西,是否可以删除这些额外的信息,这样我就不必对我的 CSS 文件进行大量修改?

这是上表在 DataGrid 之后的样子。

<table id="ContentPlaceHolder1_articleList" headertext="File Name" rules="all">
    <tr>
        <td>Header</td> <!-- I need this to be a TH?? -->
    </tr>
    <tr>
        <td>Content</td>
    </tr>
</table>

这里最大的问题是我需要标题行是<th>而不是<td>。而且我需要这张桌子只是ID而且runat="server"不是大交易,不确定它的rules="all"作用。

这是我的 asp.net 代码。

Page_Load 背后的代码:

protected void Page_Load(object sender, EventArgs e)
{
    DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("examfilemanager"));

    articleList.DataSource = dirInfo.GetFiles();
    articleList.DataBind();
}

页面:

<asp:DataGrid Enabled="false" runat="server" ID="articleList" AutoGenerateColumns="false" AlternatingItemStyle-BackColor="#EEEEEE" HeaderText="File Name">
    <Columns>
        <asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" HeaderText="File Name" />
        <asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
        <asp:BoundColumn DataField="Length" HeaderText="Filer Server" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:#,### bytes}" />
    </Columns>
</asp:DataGrid>
4

1 回答 1

3

尝试设置UseAccessibleHeader为真:

<asp:DataGrid ID="DataGrid1" runat="server" UseAccessibleHeader="true" ...>

如果可能的话,您确实应该使用GridView控件并利用控件不可用的许多功能DataGrid。在这一点上,传统的DataGrid控制更像是过时的遗物。

于 2012-04-16T15:48:21.723 回答