2

同じモデルを使用している単一ビューに 2 つの WebGrid があります。問題は、1 つの Web グリッドで並べ替えを適用すると、別の Web グリッドも並べ替えられることです。fieldNamePrefix を使用していますが、まだ問題があります。これが私のコードです:

最初の部分図:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRMEvent.Models.CRM.DatabaseEntities.CRM_Dashboard_Requests>>" %>
<%    
     var grid = new WebGrid(source: Model, defaultSort: "CRM_ID",fieldNamePrefix:"grid2", canSort: true);%>
<%=
        grid.GetHtml( htmlAttributes: new { id = "grid2" },tableStyle: "GridTable", headerStyle: "GridHeader", columns: grid.Columns(
          grid.Column(columnName: "CRM_ID", header: "CRM ID", canSort: true),
         grid.Column(columnName: "MDLNO", header: "MDLNO", canSort: true),
         grid.Column(columnName: "EMP_Name", header: "Employee", canSort: true),
         grid.Column(columnName: "SERVICE_TYPE", header: "Service Type", canSort: true),
         grid.Column(columnName: "Requested_Amount", header: "Amount", canSort: true),
                 grid.Column(columnName: "Created_Date", header: "Date", canSort: true, format: item => item.Created_Date.ToString("dd-MM-yyyy"))
         ))
   %>

2 番目の部分図:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<ApricaCRMEvent.Models.CRM.DatabaseEntities.CRM_Dashboard_Requests>>" %>
 <%    
     var grid = new WebGrid(source: Model, defaultSort: "CRM_ID",fieldNamePrefix:"grid1", canSort: true);%>
     <%=
        grid.GetHtml( htmlAttributes: new { id = "grid1" },tableStyle: "GridTable", headerStyle: "GridHeader", columns: grid.Columns(
          grid.Column(columnName: "CRM_ID", header: "CRM ID", canSort: true),
         grid.Column(columnName: "MDLNO", header: "MDLNO", canSort: true),
         grid.Column(columnName: "EMP_Name", header: "Employee", canSort: true),
         grid.Column(columnName: "SERVICE_TYPE", header: "Service Type", canSort: true),
         grid.Column(columnName: "Requested_Amount", header: "Amount", canSort: true),
                 grid.Column(columnName: "Created_Date", header: "Date", canSort: true, format: item => item.Created_Date.ToString("dd-MM-yyyy"))
         ))
   %>
4

2 に答える 2

3

webgrid には「ajaxUpdateContainerId」というプロパティがあります。このプロパティは、問題を解決するのに役立ちます。

最初の部分図

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRMEvent.Models.CRM.DatabaseEntities.CRM_Dashboard_Requests>>" %>
<%    
 var grid1 = new WebGrid(source: Model, defaultSort: "CRM_ID",fieldNamePrefix:"grid2", canSort: true, ajaxUpdateContainerId:"FirstDiv");%>
<div id="FirstDiv">
<%=
    grid1.GetHtml( htmlAttributes: new { id = "grid2" },tableStyle: "GridTable", headerStyle: "GridHeader", columns: grid.Columns(
      grid1.Column(columnName: "CRM_ID", header: "CRM ID", canSort: true),
     grid1.Column(columnName: "MDLNO", header: "MDLNO", canSort: true),
     grid1.Column(columnName: "EMP_Name", header: "Employee", canSort: true),
     grid1.Column(columnName: "SERVICE_TYPE", header: "Service Type", canSort: true),
     grid1.Column(columnName: "Requested_Amount", header: "Amount", canSort: true),
             grid1.Column(columnName: "Created_Date", header: "Date", canSort: true, format: item => item.Created_Date.ToString("dd-MM-yyyy"))
     ))
%>
</div>

2番目の部分図

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<ApricaCRMEvent.Models.CRM.DatabaseEntities.CRM_Dashboard_Requests>>" %>
 <%    
 var grid = new WebGrid(source: Model, defaultSort: "CRM_ID",fieldNamePrefix:"grid1", canSort: true, ajaxUpdateContainerId:"SecondDiv");%>
 <div id="SecondDiv">
<%=
    grid.GetHtml( htmlAttributes: new { id = "grid1" },tableStyle: "GridTable", headerStyle: "GridHeader", columns: grid.Columns(
      grid.Column(columnName: "CRM_ID", header: "CRM ID", canSort: true),
     grid.Column(columnName: "MDLNO", header: "MDLNO", canSort: true),
     grid.Column(columnName: "EMP_Name", header: "Employee", canSort: true),
     grid.Column(columnName: "SERVICE_TYPE", header: "Service Type", canSort: true),
     grid.Column(columnName: "Requested_Amount", header: "Amount", canSort: true),
             grid.Column(columnName: "Created_Date", header: "Date", canSort: true, format: item => item.Created_Date.ToString("dd-MM-yyyy"))
     ))
  %>
  </div>
于 2013-02-07T09:43:19.913 に答える
1

おそらく、両方のグリッドで同じ var 名を使用しないでください。var gridA と var gridB を試してください。

于 2013-02-07T08:50:32.467 に答える