I got table with 1 row and 3 columns(date,time,what), I want 2 of the 3 columns(time,what) in my datasource how can i do that?
我得到的表有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();
}
2 个解决方案
#1
1
I'm assuming that datagrid is a GridView? then you should be to do something like this
我假设datagrid是GridView?那么你应该做这样的事情
<asp:GridView runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="what" HeaderText="what" />
<asp:BoundField DataField="time" HeaderText="time" />
</Columns>
</asp:GridView>
#2
1
you can specify the columns in the select
您可以在select中指定列
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") });
#1
1
I'm assuming that datagrid is a GridView? then you should be to do something like this
我假设datagrid是GridView?那么你应该做这样的事情
<asp:GridView runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="what" HeaderText="what" />
<asp:BoundField DataField="time" HeaderText="time" />
</Columns>
</asp:GridView>
#2
1
you can specify the columns in the select
您可以在select中指定列
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") });