【发布时间】:2013-10-16 11:13:05
【问题描述】:
我在这里遇到了一个问题。 我在 c# 中有一个 edm 查询,根据用户选择的内容,我使用多个表填充 1(一个)网格视图控件。我让它工作并用所有数据填充表格。
我需要知道最好的方法是将列名与行中的数据一起加载。我无法使用列名预加载网格视图,因为每次数据都会有所不同。我还想要网格视图上的按钮字段,其中文本显示为表格的主要 Id。
我已经尝试了几乎所有方法,我们将不胜感激。
这是我的代码:
using (ITIncidentsEntities dbc = new ITIncidentsEntities()) {
var Query = (from c in dbc.GeneralIncidents
select c);
if (!string.IsNullOrWhiteSpace(txtDate.Text))
{
DateTime _date = Convert.ToDateTime(txtDate.Text);
Query = Query.Where(c => c.CreateDate == _date);
}
if (!string.IsNullOrWhiteSpace(txtAuthor.Text))
{
Query = Query.Where(c => c.Author.Contains(txtAuthor.Text));
}
if (!string.IsNullOrWhiteSpace(txtIncidentFormat.Text))
{
Query = Query.Where(c => c.Title == txtIncidentFormat.Text);
}
grvResults.DataSource = Query.ToArray();
grvResults.DataBind();
grvResults.Columns.Add(new ButtonField { HeaderText = "Print", Text = "??? Datavalue Field" });
}
非常感谢。
【问题讨论】:
标签: c# asp.net gridview entity-framework-4 edmx