1

私は既存の Web フォーム アプリケーションに取り組んでいます。私は強く型付けされたデータリストを持っています。ASP.NET Webフォームページにドロップダウンがあるので、ユーザーがドロップダウンリストからアイテムを選択すると、それに応じて学生リストを返す ajax 呼び出し WebMethod が静的メソッドを使用しているため、コードビハインドでデータソースをバインドできないので、 JSON 形式でデータを送信し、ASP.NET Web フォーム グリッド 'StudentFilterList_Grid' にバインドする必要があります。

コード ビハインド Web メソッド

 [WebMethod]
    public static studentList FilterStudentListInRelationToStaff(string GivenStaffID, string SelectFilterOption)
    {

 StudentList customStudentFilterList = new StudentList();
 customStudentFilterList= StaffRelay.GetStudentsForRelationship(Convert.ToInt32(GivenStaffID));  

 return customStudentFilterList;

}

ASP.NET グリッド

   <cc0:Grid ID="StudentFilterList_Grid" runat="server" FolderStyle="~/Styles/Grid" AutoGenerateColumns="false"
                     Width="100%" PageSizeOptions="5,10,20,50,100,-1" AllowFiltering="true" FilterType="ProgrammaticOnly"
                     AllowAddingRecords="false" PageSize="-1">
    <Columns>
             <cc0:Column DataField="ID" HeaderText="ID" Visible="false" />
            <cc0:Column DataField="RelationshipID" HeaderText="RelationshipID" Visible="false" />
           <cc0:Column DataField="StudentID" Width="10%" HeaderText="ID" SortExpression="StudentID" Visible="false" />
          <cc0:Column DataField="RelationshipDateStart" Width="20%" HeaderText="From" DataFormatString="{0:dd MMMM yyyy}" DataFormatString_GroupHeader="{0:dd MMMM yyyy}" SortExpression="RelationshipDateStart" />
         <cc0:Column DataField="RelationshipDateEnd" DataFormatString="{0:dd MMMM yyyy}" DataFormatString_GroupHeader="{0:dd MMMM yyyy}" Width="20%" HeaderText="To" SortExpression="RelationshipDateEnd" />
         <cc0:Column DataField="RelationshipStaffStatus" Visible="false" HeaderText="Status" SortExpression="RelationshipStaffStatus" />
        <cc0:Column DataField="RelationshipLocation" HeaderText="Locality" /> 
    </Columns>

  </cc0:Grid> 

JQuery Ajax 関数

        $("#ctl00_ContentArea_ddLStudentFilterList").change(function () {

            var selectedValue = $("#<%=ddLStudentFilterList.ClientID%> option:selected").val();

            if(selectedValue!=null)
            {
                var SelectStaffID = "37";

                $.ajax({
                    url: 'TutorForm.aspx/FilterStudentListInRelationToStaff',
                    type: "POST",
                    data: JSON.stringify({ GivenStaffID: SelectStaffID, SelectFilterOption: selectedValue }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {

                       alert("success" + response.d[0].RelationshipID);

     for (var index = 0; index <= response.d.length - 1; index++) {

     var indexStudentFullName = response.d[index].Forenames + "-" + response.d[index].Surnames;

    //  alert(response.d[index].ID + "  RelationshipID  " + RelationshipID + "  StudentID " + StudentID + "  RelationshipDateStart " + RelationshipDateStart + "  RelationshipDateEnd" + RelationshipDateEnd + "  RelationshipStaffStatus  " + RelationshipStaffStatus + "  StudentFullName " + indexStudentFullName);

                            ????????????????????????????????

     }

                    },
                    failure: function (response) {
                        alert(response.d);
                    }
                }).done(function (response) {

                });
            }

  });

上記のコードは、json でデータを取得していることを確認するため、上記のアラートは response.d[0].RelationshipID に応答します。

4

0 に答える 0