0

我的 .aspx 页面中有以下内容:

<asp:GridView ID="Table1" runat="server" AutoGenerateColumns="False"    BorderColor="Black" OnRowCreated="Table1_RowCreated" OnRowDataBound="Table1_RowDataBound" CellPadding="3" CellSpacing="0" DataSourceID="Table1DataSrc" DataKeyNames="Field1">
<Columns>
<asp:BoundField DataField="Field1" HeaderText="Field1" SortExpression="Field1">
     <ItemStyle HorizontalAlign="Left" Font-Size="8" Wrap="false" />
     <HeaderStyle CssClass="header" Font-Size="8" />
 </asp:BoundField>
 </Columns>
 </asp:GridView>

gridview 有一个加载几个字段的数据源。在我后面的 C# 代码中,我有以下函数,它运行 LINQ 查询来处理存储过程(在与我的其他数据源不同的服务器上)

    private void RenderTables()
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
        DataTable dt = new DataTable();

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("sp_special", conn);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@AmIY", "Y");
            adapter.SelectCommand = cmd;
            adapter.Fill(dt);
            adapter.Dispose();
            conn.Close();
        }
        var enumvar = dt.AsEnumerable();
        var query = from x in enumvar
                    orderby x.Field<string>(3)
                    select new 
                    { 
                        Field3 = x.Field<string>(3),
                        Field4 = x.Field<int>(4),
                    };
        //I do some data manipulation using LINQ, but omitted here
        //do something with query.....
    }

如何将新列 Field3 和 Field4 添加到我的 Gridview 并绑定这些新记录?我不想在任一服务器上的临时表中存储任何内容

4

1 回答 1

0

它会像这样工作......

<asp:BoundField DataField="Field3" HeaderText="Field3" SortExpression="Field3"> 
<asp:BoundField DataField="Field4" HeaderText="Field4" SortExpression="Field4">
于 2012-11-07T07:50:54.063 回答