Здравствуйте! я пишу пробный пример с компонентом AJAXEnabledWCFservice. Данные у меня отображаются в контриле LictView который описан в файле default.aspx
| Код | <asp:ListView ID="ListView1" runat="server"> <LayoutTemplate> <table id="header" runat="server" class="yui-grid" cellspacing="0" border="0"> <tr> <th> ID </th> <th> First Name </th> <th> Last Name </th> <th> Car </th> <th>Edit</th><th>Remove</th> </tr> <tr id="itemPlaceholder" runat="server" /> </table> <br/> <label class="addEmployee" runat="server" style="cursor:pointer;color:Blue; text-decoration:underline;">Add</label> </LayoutTemplate> <ItemTemplate> <tr id="row" runat="server" > <td id="Eid"><%# Eval("ID") %></td> <td><%# Eval("FirstName")%></td> <td><%# Eval("LastName")%></td> <td><%# Eval("CarID")%></td> <td><label runat="server" id="btnEdit" style="cursor:pointer; color:Blue; text-decoration:underline;">Edit</label></td> <td><label runat="server" class="btnRemove" title='<%#Eval("ID") %>' style="cursor:pointer; color:Blue; text-decoration:underline;">Remove</label></td> </tr> </ItemTemplate> </asp:ListView>
|
при шелчке addEmployee обрабатывается событие в скрипте
| Код | $(".addEmployee").click(function(ev) { $.ajax({ type = "POST"; url = "/Code/WebService.svc/AddList"; data = '{"firstName":"'+$("#TextBoxFirstName").val()+'","lastName":"'+$("#TextBoxLastName").val()+'","car":"'+$("#TextBoxCar").val()+'"}'; contentType = "application/json; charset=utf-8"; dataType = "json"; processData = true; success : function(msg) {//On Successfull service call }, error : function(msg) {// When Service call fails } }); });
|
добавление работает потом в файле default.aspx.cs прорисовать след. образом
| Код | public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Code.WebService webService = new Code.WebService(); ListView1.DataSource = webService.GetAllList(); ListView1.DataBind(); ListView1.DataSource = null; } } }
|
код метода GetAllList
| Код | [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] List<Employee> GetAllList();
|
Контрила листвиев не прорисовывается. Может скажет кто нибудь в чем дело? |