标题如何将分页wcf用作数据源? Dataservicequery有setentitysetpagesize选择的记录有限。在这种情况下,它应该如何像数据源一样工作。如果将其绑定到Web控件,则在查询所有记录时,总记录将是错误的,并且分页也具有分页。由于此原因,我已经疯了。
答案 0 :(得分:2)
您需要使用泛型类作为返回类型,并使该类可序列化,然后在前端使用Object数据源。我确信它有效。
像: Bizz层作为W.C.F服务
public List<Employee> GetEmployees()
{
try
{
List<Employee> emp = new List<Employee>();
emp.Add(new Employee { Code = 1, DepartMentCode = 2, FatherName = "FatherName", ManagerCode = 2, Name = "Bilal",ManagerName="mnagername", PhoneNumber = "24421" });
return emp;
}
catch (TimeoutException te)
{
throw te;
}
catch (FaultException fe)
{
throw new FaultException();
}
catch (CommunicationException ce)
{
throw new CommunicationException();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (client != null)
{
client.Close();
}
}
}
//实体类
[Serializable()]
[DataContract()]
public class Employee
{
[DataMember]
public int Code { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string FatherName { get; set; }
[DataMember]
public string PhoneNumber { get; set; }
[DataMember]
public int DepartMentCode { get; set; }
[DataMember]
public int ManagerCode { get; set; }
[DataMember]
public string ManagerName { get; set; }
}
//这是页面级代码。我希望你能理解这一点。
<div class="EmployeeMain">
<div class="link" onclick="Show_Popup();">
New Employee</div>
<fieldset>
<legend>Employees Details </legend>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ODSEmployee"
OnRowEditing="GridView1_RowEditing" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" Width="100%"
AllowPaging="True">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<Columns>
<asp:BoundField FooterText="EmployeeID" DataField="Code" HeaderText="EmployeeID" />
<asp:BoundField FooterText="Name" DataField="Name" HeaderText="Name" />
<asp:BoundField FooterText="Father Name" DataField="FatherName" HeaderText="Father Name" />
<asp:BoundField FooterText="Phone Number" DataField="PhoneNumber" HeaderText="Phone Number" />
<asp:TemplateField FooterText="manager" HeaderText="Manager">
<ItemTemplate>
<asp:Label ID="lblMangerName" Text='<%# Eval("ManagerName") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlManager" runat="server" DataSourceID="ManagersDataSource"
DataTextField="ManagerName" DataValueField="ManagerCode" SelectedValue='<%# Bind("ManagerCode") %>'
AppendDataBoundItems="True">
</asp:DropDownList>
<asp:ObjectDataSource runat="server" ID="ManagersDataSource" SelectMethod="GetManagers"
TypeName="mytest.WebApplication.BizzLayerService.EmployeeClient"></asp:ObjectDataSource>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
<asp:ObjectDataSource ID="ODSEmployee" runat="server" DeleteMethod="DeleteEmployeeRecord"
InsertMethod="SaveEmployeeRecord" SelectMethod="GetEmployees" TypeName="mytest.WebApplication.BizzLayerService.EmployeeClient"
UpdateMethod="UpdateEmployeeRecord">
<DeleteParameters>
<asp:Parameter Name="empCode" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="empCode" Type="Int32" />
<asp:Parameter Name="empName" Type="String" />
<asp:Parameter Name="empFatherName" Type="String" />
<asp:Parameter Name="empPhoneNumber" Type="String" />
<asp:Parameter Name="empAddress" Type="String" />
<asp:Parameter Name="empDeparmentCode" Type="Int32" />
<asp:Parameter Name="EmpManagerCode" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="empCode" Type="Int32" />
<asp:Parameter Name="empName" Type="String" />
<asp:Parameter Name="empFatherName" Type="String" />
<asp:Parameter Name="empPhoneNumber" Type="String" />
<asp:Parameter Name="empAddress" Type="String" />
<asp:Parameter Name="empDeparmentCode" Type="Int32" />
<asp:Parameter Name="EmpManagerCode" Type="Int32" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
</fieldset>
</div>
<div class="newAcount">
<table>
<tr>
<td colspan="2">
<h1>New Employee Record</h1>
</td>
</tr>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Father Name
</td>
<td>
<asp:TextBox ID="txtFathername" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Phone Number
</td>
<td>
<asp:TextBox ID="txtPhonuNumber" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Department code
</td>
<td>
<asp:DropDownList ID="ddlDeptCode" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Manager Code
</td>
<td>
<asp:DropDownList ID="ddlManagerName" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSaveRecord" runat="server" Text="Button" />
</td>
<td>
<input id="Button1" type="button" value="close" onclick="Close_Popup()" />
</td>
</tr>
</table>
</div>