我得到的表有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();
}
答案 0 :(得分: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>
答案 1 :(得分: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") });