如何在gridview中重命名我的列(别名)?

时间:2016-10-17 16:23:33

标签: asp.net alias

我在这里尝试更改Visual Studio 2012中C#asp.net页面的列名别名有点难过。这个页面允许用户按列,TankNum,CL和日期范围搜索/过滤过滤数据。我希望TankNum的gridview列名称为Tank。

完整代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">

</head>
<body>
<form id="form1" runat="server">

    <div>
<asp:GridView ID="GridView" DataSourceID="SqlDataSource1" CellPadding="5" AllowPaging="True" PageSize="5" runat="server" AutoGenerateColumns="true">
    <HeaderStyle BackColor="#989898" ForeColor="white" />

     </asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=Computer\sqlexpress;Initial Catalog=DB;Integrated Security=True"

SelectCommand="SELECT TankNum, GD, CL FROM tblHistory2"
FilterExpression="GD >= '#{0}#' AND GD <= '#{1}#' AND TankNum LIKE '{2}%' AND CL LIKE '{3}%'">

    <FilterParameters>
        <asp:ControlParameter Name="Date" ControlID="tbDateFrom" Type="DateTime" PropertyName="Text" />
        <asp:ControlParameter Name=" Date" ControlID="tbDateTo" Type="DateTime" PropertyName="Text" />
        <asp:ControlParameter ControlID="txtTankNum" Name="TankNum" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
         <asp:ControlParameter ControlID="txtCL" Name="CL" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
    </FilterParameters>
</asp:SqlDataSource>

<br />

           <th>Tank</th>&nbsp;
    <td><asp:TextBox ID="txtTankNum" runat="server" Width="96px"> </asp:TextBox>Clock&nbsp; </td>
    <td ><asp:TextBox ID="txtCL" runat="server" Width="104px"></asp:TextBox></td>

        <p></p>

Enter the Date Range: 
<p>
</p>
        <td><asp:TextBox ID="tbDateFrom" runat="server" ReadOnly = "false">01/01/2000</asp:TextBox></td>
    <td >&nbsp;</td>
    <td><asp:TextBox ID="tbDateTo" runat="server" ReadOnly = "false">12/31/2017</asp:TextBox></td>
        <input type="submit" id="Submit1" runat="server" />

</div>
</form>
</body>
</html>

我试着这样做:

SelectCommand="SELECT TankNum AS Tank, GD, CL FROM tblHistory2"

但我收到此错误:找不到列[TankNum]。

再次,这工作正常我只是无法想象如何更改列的别名。有什么建议吗?

0 个答案:

没有答案