我尝试在grdiview
的下拉列表中添加批准类型值GridView的
<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();
因为文档表中没有approveid列,所以这只在批准表中。 我尝试在gridview
的下拉列表中显示approve.reject和pending当我调试代码时,它向我显示页面加载代码中的错误..
A field or property with the name 'ApproveID' was not found on the selected data source.
答案 0 :(得分:3)
您绑定到网格视图的数据源不包含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
希望这会有所帮助..
答案 1 :(得分:1)
您需要在结果集中显示ApproveID
列。也就是说,在SELECT
中添加列。如果它在表中被加入,你需要做这样的事情:
select [JoinedTable].[Column] AS ApproveID ...