我尝试在grdiview的dropdownlist中添加批准的类型值

网格视图

<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();


由于在文档表中没有批准列,因此仅在批准表中。
我尝试在gridview的dropdownlist中显示approve.reject和pending

当我调试代码时,它向我显示页面加载代码中的错误。

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


希望这可以帮助..

09-25 16:34