【发布时间】:2017-11-26 08:55:20
【问题描述】:
我有一个 GridView,我从 Load 后面的代码中填充。进入编辑模式后,我需要将一列作为 DropDownList 填充另一个表中的字段。
由于 GridView 中的所有数据在非编辑视图(选择视图?)中都是正确的,我认为它与 DataTextField 或 DataValueField 有关。
网格视图:
<asp:GridView runat="server" ID="gvOFO" AllowPaging="true" PageSize="100" AllowSorting="true" AutoGenerateColumns="false" CssClass="table table-condensed text-center" DataKeyNames="OFOKey" OnRowCancelingEdit="gvOFO_RowCancelingEdit" OnRowCommand="gvOFO_RowCommand" OnRowDataBound="gvOFO_RowDataBound" OnRowDeleting="gvOFO_RowDeleting" OnRowEditing="gvOFO_RowEditing" OnRowUpdating="gvOFO_RowUpdating" OnSorting="gvOFO_Sorting" OnPageIndexChanging="gvOFO_PageIndexChanging">
<columns>
<templatefield><itemtemplate>column1label</itemtemplate></templatefield>
<templatefield><itemtemplate>column2label</itemtemplate></templatefield>
<templatefield>
<itemtemplate>column3label</itemtemplate>
<edititemtemplate>
<asp:DropDownList runat="server" ID="ddlStatus" DataTextField="OFOstatus" DataValueField="OFOstatus" CssClass="form-control" />
</edititemtemplate>
</templatefield>
</columns>
</gridview>
表1:
OFOKey int 身份 (PK)
日期日期时间
ReceiptPointGroupKey int(FK 到另一个表)
OFOstatus varchar(FK 到表 2)
表 2:
DayTypeKey int 身份 (PK)
DayTypeName varchar
为什么我不知道,但是这些表是由 OFOstatus 和 DayTypeName 链接的(我建议通过 int PK 链接到数据库的创建者,但无论它们如何链接,我在填充DDL)
绑定方法:
void BindGrid()
{
using (EntityDB dc = new EntityDB())
{
var ds = (from ofo in dc.OFOs
//the join just overlays the name over the int FK of the OFO table
join zone in dc.ReceiptPointGroups on ofo.ReceiptPointGroupKey equals zone.ReceiptPointGroupKey
//-----------------------------------------------------------------
select new { ofo.OFOKey, ofo.Date, zone.ReceiptPointGroupName, ofo.OFOstatus }).ToList();
gv.DataBind();
}
【问题讨论】:
标签: c# entity-framework linq gridview ddl