1

I am working on existing webform application. I have strongly typed data list. Now I have dropdown in ASP.NET webform page, so when user choose item from dropdown list, ajax call WebMethod which will return student list accordingly, Now because I am using static method, I cannot bind data source in code-behind so what I need to do is send data in JSON format and bind with ASP.NET Webform grid 'StudentFilterList_Grid'.

Code-Behind WebMethod

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

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

 return customStudentFilterList;

}

ASP.NET Grid

   <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 Function

        $("#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) {

                });
            }

  });

the above code confirm that I am getting data in json, so above alert does given me answer response.d[0].RelationshipID

K.Z
  • 5,201
  • 25
  • 104
  • 240

0 Answers0