0

我有 1 行和 3 列(日期、时间、内容)的表,我想要数据源中的 3 列中的 2 列(时间、内容)我该怎么做?

var table = (from r in socialEvents.AsEnumerable()
                         where r.Field<DateTime>("Date") >= Calendar1.SelectedDate.Date &&
                               r.Field<DateTime>("Date") <= Calendar1.SelectedDate.AddDays(1)
                         select r).CopyToDataTable();    

    if (table.Rows.Count > 0)
                {
                    DataGrid1.Visible = true;
                    DataGrid1.DataSource = table;
                    DataGrid1.DataBind();
                }
4

2 回答 2

1

我假设datagrid是一个GridView?那么你应该做这样的事情

<asp:GridView runat="server" AutoGenerateColumns="false"  >
<Columns>
    <asp:BoundField DataField="what" HeaderText="what" />
    <asp:BoundField DataField="time" HeaderText="time"  />        
</Columns>

</asp:GridView>
于 2013-02-27T13:09:13.653 回答
1

您可以在选择中指定列

var table = (from r in socialEvents.AsEnumerable()
                         where r.Field<DateTime>("Date") >= Calendar1.SelectedDate.Date &&
                               r.Field<DateTime>("Date") <= Calendar1.SelectedDate.AddDays(1)
                         select new {time = r.Field<DateTime>("Date"), what = r.Field<data_type>("what") });
于 2013-02-27T13:29:15.543 回答