我有一個網格視圖內的下拉列表。這裏是gridview的如何在GridView中設置dropdownlist的選定值?
<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>
這裏是後面的代碼現在的問題是內部的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;
}
綁定。但下拉列表不與數據庫數據綁定。 SelectedValue
財產是給錯誤,如:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'PROGRAMME'.
你在哪裏綁定下拉列表? – dansasu11
我已經在Gridview_RowDataBound事件中完成了 –
您必須先綁定dropdownlist數據源,然後才能設置selectedvalue – Sandeep