2

カスケード ドロップダウンのセットがありますが、ページがロードされたときにデフォルトの selectedvalue がそこにあるようにします。現在、私のドロップダウンリストはデフォルトで DDL の最初の値になっています。(ASP.NET C#)

そしてコード(問題は「DDL_Assignment」ドロップダウンにあります)...

<tr>
        <td>
            <b>Position Type:</b>
        </td>
        <td>
            <asp:Label ID="Lbl_PositionType" runat="server" />
        </td>
    </tr>
    <tr id="TR_Occupation" runat="server">
        <td>
            <b>Select Occupation:</b>
        </td>
        <td>
            <asp:DropDownList ID="DDL_Occupation" runat="server" DataSourceID="DataSource_Occupation" DataTextField="Position" DataValueField="Position"
                AutoPostBack="True" OnSelectedIndexChanged="DDL_Occupation_SelectedIndexChanged">
            </asp:DropDownList>

            <asp:ObjectDataSource ID="DataSource_Occupation" runat="server" 
                OldValuesParameterFormatString="original_{0}" SelectMethod="GetPositions" 
                TypeName="HumanResourceTableAdapters.PositionTableAdapter">
                <SelectParameters>
                    <asp:ControlParameter ControlID="Lbl_PositionType" Name="PositionType" 
                        PropertyName="Text" Type="String" />
                </SelectParameters>
            </asp:ObjectDataSource>

            <asp:TextBox ID="TB_Occupation" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
            <b>Select Assignment Name:</b>
        </td>
        <td>
            <asp:UpdatePanel ID="UP_Assignment" runat="server">
                <ContentTemplate>
                    <asp:DropDownList ID="DDL_Assignment" runat="server"
                         AutoPostBack="True"
                        OnSelectedIndexChanged="DDL_Assignment_SelectedIndexChanged" />
                    <asp:ObjectDataSource ID="DataSource_Assignment" runat="server" 
                        OldValuesParameterFormatString="original_{0}" SelectMethod="GetAssignments" 
                        TypeName="HumanResourceTableAdapters.PositionTableAdapter">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DDL_Occupation" Name="Position" 
                                PropertyName="SelectedValue" Type="String" />
                            <asp:ControlParameter ControlID="Lbl_PositionType" Name="PositionType" 
                                PropertyName="Text" Type="String" />
                        </SelectParameters>
                    </asp:ObjectDataSource>
                    <asp:ObjectDataSource ID="DataSource_AssignmentHourly" runat="server" 
                        OldValuesParameterFormatString="original_{0}" 
                        SelectMethod="GetAssignmentByPosType" 
                        TypeName="HumanResourceTableAdapters.PositionTableAdapter">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="Lbl_PositionType" Name="PositionType" 
                                PropertyName="Text" Type="String" />
                        </SelectParameters>
                    </asp:ObjectDataSource>
                    <asp:TextBox ID="TB_Assignment" runat="server" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="DDL_Occupation" EventName="SelectedIndexChanged" />
                </Triggers>
            </asp:UpdatePanel>

        </td>
    </tr>

コードの背後にある「posRow.Assignment」は正しい値を出力します...ドロップダウンリストは何らかの理由でそれを取り込んでいません

Position1TableAdapter position1TableAdapter =
                new Position1TableAdapter();
            HumanResource.Position1Row posRow =
                position1TableAdapter.GetData(Convert.ToInt32(Request.QueryString["PositionID"]))[0];

            DDL_Assignment.DataTextField = "AssignmentName";
            DDL_Assignment.DataValueField = "AssignmentName";
            DDL_Assignment.DataSourceID = "DataSource_Assignment";

            DDL_Occupation.SelectedValue = posRow.Position;
            DDL_Assignment.SelectedValue = posRow.Assignment;
            TB_Assignment.Text = posRow.Assignment;
            TB_Replaced.Text = posRow.Replaced;
            DDL_PositionDays.SelectedValue = posRow.PositionDays.ToString();
            DDL_ContractDays.SelectedValue = posRow.ContractDays.ToString();
            DDL_PositionHours.SelectedValue = posRow.PositionHours.ToString();
            DDL_Location.SelectedValue = posRow.Location.ToString();
            TB_Contract.Text = posRow.IsContractInformationNull() ? null : posRow.ContractInformation;
            DDL_1yrContractReason.SelectedValue = posRow.Isposition_1yrcntrctrsnIDNull() ? null : posRow.position_1yrcntrctrsnID.ToString();
            RBL_Administrator.SelectedValue = posRow.Administrator.ToString();
            RBL_CertifiedSalarySchedule.SelectedValue = posRow.clas_CertifiedScheduleInd.ToString();
            RBL_OvertimeExempt.SelectedValue = posRow.position_OvertimeExemptInd.ToString();
            RBL_ExtendedContractExempt.SelectedValue = posRow.position_ExtContractExemptInd.ToString();
            RBL_LongevityException.SelectedValue = posRow.Longevity_Exception_Indicator.ToString();
            RBL_NoStepIncrease.SelectedValue = posRow.position_NoStepInd.ToString();
            RBL_JobShare.SelectedValue = posRow.position_JobShareInd.ToString();

他に詳細が必要な場合はお知らせください

4

3 に答える 3

0

各 ddl の前にデータバインドする必要がある

Position1TableAdapter position1TableAdapter =
                new Position1TableAdapter();
            HumanResource.Position1Row posRow =
                position1TableAdapter.GetData(Convert.ToInt32(Request.QueryString["PositionID"]))[0];

            DDL_Assignment.DataTextField = "AssignmentName";
            DDL_Assignment.DataValueField = "AssignmentName";
            DDL_Assignment.DataSourceID = "DataSource_Assignment";

            DDL_Occupation.DataBind();
            DDL_Occupation.SelectedValue = posRow.Position;

            DDL_Assignment.DataBind();
            DDL_Assignment.SelectedValue = posRow.Assignment;

            TB_Replaced.Text = posRow.IsReplacedNull() ? null : posRow.Replaced;

            DDL_PositionDays.DataBind();
            DDL_PositionDays.SelectedValue = posRow.PositionDays.ToString();

            DDL_ContractDays.DataBind();
            DDL_ContractDays.SelectedValue = posRow.ContractDays.ToString();

            DDL_PositionHours.DataBind();
            DDL_PositionHours.SelectedValue = posRow.PositionHours.ToString();
于 2011-04-05T21:54:56.413 に答える
0

それ以外の

DDL_Occupation.SelectedValue = posRow.Position;

必要SelectedIndexですか?

DDL_Occupation.SelectedIndex = posRow.Position;
于 2011-04-01T21:08:45.927 に答える
0

あなたのコードを追加する必要がありますウィッチは、ページの読み込みでドロップダウンリストの選択された値を設定しています。発生したイベントでドロップダウン リストの選択した値を変更すると、選択した値が設定されません。ページのページロードイベントでセッターメソッドを呼び出すだけです。あなたの問題は解決されます。

于 2011-04-01T21:06:13.357 に答える