在所选数据源上找不到名称为“ApproveID”的字段或属性
本文关键字:ApproveID 字段 属性 数据源 找不到 | 更新日期: 2023-09-27 18:33:56
我尝试在 grdiView 的下拉列表中添加批准类型值
网格视图
<asp:BoundField HeaderText="ApproveID" DataField="ApproveID"></asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server"
class="vpb_dropdown">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
.SQL
ALTER procedure [dbo].[viewdocid]
as
select dbo.DocumentInfo.DocID,dbo.DocumentInfo.DocName,dbo.DocumentInfo.Uploadfile,dbo.DocType.DocType,dbo.Department.DepType
from dbo.DocumentInfo left join dbo.DocType on dbo.DocumentInfo.DocTypeID=dbo.DocType.DocTypeID left join
dbo.Department on dbo.DocumentInfo.DepID=dbo.Department.DepID
C#
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Find the DropDownList in the Row
DropDownList ddlvalue = (e.Row.FindControl("DropDownList4") as
DropDownList);
ddlvalue .DataSource = GetData("SELECT ApproveID,ApproveType FROM
ApproveType");
ddlvalue .DataTextField = "ApproveType";
ddlvalue .DataValueField = "ApproveID";
ddlvalue .DataBind();
//Add Default Item in the DropDownList
ddlvalue.Items.Insert(0, new ListItem("Please select"));
//Select the Country of Customer in DropDownList
//string country = (e.Row.FindControl("lblCountry") as Label).Text;
//ddlvalue.Items.FindByValue(country).Selected = true;
}
}
我在页面加载中添加此代码
GrdFileApprove.DataSource = dd.gdocid();
GrdFileApprove.DataBind();
其中,由于文档表中没有批准列,因此仅在批准表中。我尝试在网格视图的下拉列表中显示批准.拒绝和挂起
当我调试代码时,它显示页面加载代码中的错误。
A field or property with the name 'ApproveID' was not found on the selected data source.
绑定到网格视图的数据源不包含 Arrpove 类型列,因此显然会出现该错误。
您需要通过使用表之间的联接来获取该Approve id
。
网格视图一次只能保存一个结果集
ALTER procedure [dbo].[viewdocid]
as
select A.ApproveID,A.ApproveType dbo.DocumentInfo.DocID,dbo.DocumentInfo.DocName,dbo.DocumentInfo.Uploadfile,dbo.DocType.DocType,dbo.Department.DepType
from dbo.DocumentInfo left join dbo.DocType on dbo.DocumentInfo.DocTypeID=dbo.DocType.DocTypeID left join
dbo.Department on dbo.DocumentInfo.DepID=dbo.Department.DepID
left join dbo.ApproveType A on dbo.DocumentInfo.DocID=A.Approvetype
希望这有帮助..
您需要在结果集中存在ApproveID
列。也就是说,在 SELECT
中包含该列。如果它在正在连接的表中,则需要执行以下操作:
select [JoinedTable].[Column] AS ApproveID ...