-1

我在网格视图中有一个下拉列表。这是网格视图

<asp:GridView ID="gvFabricDetails" runat="server" AutoGenerateColumns="False" ShowFooter="True" CellPadding="4" ForeColor="#333333" GridLines="None" Width="49px" onrowdatabound="gvFabricDetails_RowDataBound" >
    <Columns>
        <asp:TemplateField HeaderText="Programme">
            <ItemTemplate>
                <asp:DropDownList ID="ddlProgramme" DataTextField="PROGRAMME_NAME" DataValueField="PROGRAMME_ID" SelectedValue='<%# Bind("PROGRAMME") %>' AppendDataBoundItems="true"  runat="server"></asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Lot/Style">
            <ItemTemplate>
                <asp:TextBox ID="txtLot" TabIndex="2" Text='<%# Bind("LOT_STYLE") %>' runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Art#">
        <ItemTemplate>
            <asp:TextBox ID="txtArt" TabIndex="3" Text='<%# Bind("ART") %>' runat="server" ></asp:TextBox>
        </ItemTemplate>
    </asp:TemplateField>
</asp:GridView>

这是绑定数据的代码

public DataTable loadFabricInfos()
{
    DataTable dt = new DataTable();
    string sql = "";

    sql = "SELECT PROGRAMME,LOT_STYLE,ART FROM FABRICISSUE";

    OracleCommand objCommand = new OracleCommand(sql);
    OracleDataAdapter objDataAdapter = new OracleDataAdapter(objCommand);
    using (OracleConnection strConn = GetConnection())
    {
        try
        {
            objCommand.Connection = strConn;
            strConn.Open();
            objDataAdapter.Fill(dt);
        }

        catch (Exception ex)
        {
            throw new Exception("Error : " + ex.Message);
        }

        finally
        {
            strConn.Close();
        }
    }

    return dt;
}

现在的问题是gridview中的其他文本框正在获取数据。但下拉列表未与数据库数据绑定。SelectedValue属性给出错误,如:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'PROGRAMME'.

4

2 回答 2

1

更改此行 您的查询是 SELECT PROGRAM , LOT_STYLE , ART FROM FABRICISSUE

您应该使用您的查询字段

DataTextField=" LOT_STYLE "DataValueField=" PROGRAM "SelectedValue='<%#Bind(" PROGRAM ")%>'

<asp:DropDownList ID="ddlProgramme" DataTextField="PROGRAMME_NAME" DataValueField="PROGRAMME" SelectedValue='<%# Bind("PROGRAMME") %>' AppendDataBoundItems="true"  runat="server"></asp:DropDownList>
于 2015-10-13T11:55:21.487 回答
0

您可以在后面的代码中将其绑定到 radgrid Itemdatabond 事件中:

private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if ((e.Item is GridDataItem)) {
        GridDataItem item = e.Item;
        DropDownList list = (DropDownList)item.FindControl("ddlProgramme");
        list.SelectedValue = DataBinder.Eval(item.DataItem, "<Datafield_name>").ToString();
    }
}

希望这可以帮助...

于 2015-10-14T05:50:33.850 回答