我正在使用以下代码绑定并在网格视图中显示下拉列表。但它总是显示第一项,无论数据库表有第二项还是第三项。
private void BindData1()
{
DataSet7TableAdapters.sp_getall_trv_config_masterTableAdapter TA = new DataSet7TableAdapters.sp_getall_trv_config_masterTableAdapter();
DataSet7.sp_getall_trv_config_masterDataTable DS = TA.GetData();
if (DS.Rows.Count > 0)
{
GridView2.DataSource = DS;
GridView2.DataBind();
}
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
Control ctrl = e.Row.FindControl("DDL_STATUS_FT");
if (ctrl != null)
{
DropDownList dd = ctrl as DropDownList;
DataSet7TableAdapters.sp_getall_trv_masterTableAdapter TA = new DataSet7TableAdapters.sp_getall_trv_masterTableAdapter();
DataSet7.sp_getall_trv_masterDataTable DS = TA.GetData();
dd.DataTextField = "fld_TName";
dd.DataValueField = "fld_id";
dd.DataSource = DS;
dd.DataBind();
}
}
}
设计规范:
<asp:TemplateField ItemStyle-Width="100px" HeaderText="TYPE">
<ItemTemplate>
<asp:DropDownList ID="DDL_STATUS" runat="server" AutoPostBack="true" Enabled="false" >
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DDL_edit_STATUS" runat="server" AutoPostBack="true">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="DDL_STATUS_FT" runat="server" AutoPostBack="true">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
我想将保存数据显示为选定值。但是现在第一个项目总是显示在下拉列表中。请帮我这样做..