我正在处理现有的webform应用程序。我有强类型数据列表。现在我在ASP.NET webform页面下拉,所以当用户从下拉列表中选择项目时,ajax调用WebMethod会相应地返回学生列表,现在因为我使用的是静态方法,所以我无法在代码隐藏中绑定数据源所以我需要做的是以JSON格式发送数据并与ASP.NET Webform网格'StudentFilterList_Grid'绑定。
[WebMethod]
public static studentList FilterStudentListInRelationToStaff(string GivenStaffID, string SelectFilterOption)
{
StudentList customStudentFilterList = new StudentList();
customStudentFilterList= StaffRelay.GetStudentsForRelationship(Convert.ToInt32(GivenStaffID));
return customStudentFilterList;
}
<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>
$("#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