0

我希望今天能在这里得到一些帮助,因为我正在努力找出为什么会发生这种情况。我在编辑模式的详细视图中有下拉列表,因此当从下拉列表中选择类别并点击更新按钮时;它不会保存在我的表中选择的类别。它显示一个 NULL 值。这是我的代码:ASPX 代码:

<asp:DetailsView ID="DetailsView2" runat="server" OnDataBound="DV_DataBound"  AutoGenerateRows="False" 
    BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" 
    CellPadding="4" CellSpacing="2" DataKeyNames="Post_ID" 
    DataSourceID="DetailsEntryView_DS" ForeColor="Black" Height="50px" 
    Width="800px" DefaultMode="Edit">
    <EditRowStyle BackColor="#FFFFCC" Font-Bold="True" ForeColor="#003366" BorderStyle="Groove" />
    <Fields>
        <asp:BoundField DataField="Post_ID" HeaderText="RCA ID" ReadOnly="True" SortExpression="Post_ID" />
        <asp:TemplateField HeaderText="Root Cause Category" SortExpression="Root_Cause_Category">           
            <EditItemTemplate>
                <asp:DropDownList ID="ddlCountry" runat="server" AppendDataBoundItems="True" 
                    AutoPostBack="True" DataSourceID="DD_DS" 
                    DataTextField="Root_Cause_Category" DataValueField="Root_Cause_Category" > 
                </asp:DropDownList> 

                <asp:SqlDataSource ID="DD_DS" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DSRConnectionString %>" 
                    SelectCommand="SELECT DISTINCT [Root_Cause_Category] FROM [RCA_Category_List]">
                </asp:SqlDataSource>

            </EditItemTemplate>

//这是后面的代码:

 protected void DV_DataBound(object sender, EventArgs e)
    {
        if (DetailsView2.CurrentMode == DetailsViewMode.Edit)
        {
            //Find Drop down list from aspx page
            DropDownList ddlCountry = DetailsView2.FindControl("ddlCountry") as DropDownList;
            //check ddlCountry is not null || country drop down list is found
            if (ddlCountry != null)
            {
                //Bind countries data to ddlCountry 
                ddlCountry.DataTextField = "Root_Cause_Category";
                ddlCountry.DataValueField = "Root_Cause_Category";
                ddlCountry.DataSource = DD_DS;
                //custom method that gets all countries 
                ddlCountry.DataBind();
            }
        }
    }

那么我在这里缺少什么?

4

0 回答 0