当用户选择一行并单击按钮时,我试图在客户端显示选定的行。

我尝试了来自此devexpress link的代码

我在代码中尝试了相同的情况,但是会引发错误

这是我的代码

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" Width="100%" SettingsBehavior-AllowSelectByRowClick="True" OnSelectionChanged="btnSearch_Click">
    <Settings HorizontalScrollBarMode="Visible" ShowFilterRow="True" ShowGroupedColumns="True" ShowTitlePanel="True" ShowGroupPanel="True" />

    <SettingsSearchPanel Visible="True" />
    <Columns>
        <dx:GridViewCommandColumn  ShowSelectCheckbox="true" VisibleIndex="0"></dx:GridViewCommandColumn>
        <dx:GridViewDataTextColumn FieldName="Status" ReadOnly="True" VisibleIndex="0"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="WorksheetID" VisibleIndex="1"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="POTitle" VisibleIndex="2" Width="200px" ExportWidth="100" MinWidth="100"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="FromStoreName" VisibleIndex="3"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="FromPONumber" VisibleIndex="4"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="ToStoreName" VisibleIndex="5"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="ToPONumber" VisibleIndex="6"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="FromStoreID" VisibleIndex="7"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="ToStoreID" VisibleIndex="8"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="FromPlacementStatus" ReadOnly="True" VisibleIndex="9"></dx:GridViewDataTextColumn>
        <dx:GridViewDataDateColumn FieldName="FromDatePlaced" VisibleIndex="10"></dx:GridViewDataDateColumn>
        <dx:GridViewDataTextColumn FieldName="ToPlacementStatus" ReadOnly="True" VisibleIndex="11"></dx:GridViewDataTextColumn>
        <dx:GridViewDataDateColumn FieldName="ToDatePlaced" VisibleIndex="12"></dx:GridViewDataDateColumn>
        <dx:GridViewDataDateColumn FieldName="LastUpdated" VisibleIndex="13"></dx:GridViewDataDateColumn>
        <dx:GridViewDataTextColumn FieldName="IssueQty" VisibleIndex="14">            </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="IssueValue" VisibleIndex="15"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="ReceivedQty" VisibleIndex="16"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="ReceivedValue" VisibleIndex="17"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="DiscrepancyQty" ReadOnly="True" VisibleIndex="18"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="Discrepancy" ReadOnly="True" VisibleIndex="19"></dx:GridViewDataTextColumn>
    </Columns>

</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:HQMatajer13 %>"
    SelectCommand="select top 10000
        CASE WHEN FromStatus = 0 AND (ToStatus = 0 OR ToStatus IS NULL OR (ToStoreID = 0 AND WorksheetID = 0)) THEN 'Open'
       WHEN ToStatus = 0 AND (FromStatus IS NULL OR (FromStoreID = 0 AND WorksheetID = 0)) THEN 'Open'
       WHEN FromStatus = 2 AND (ToStatus = 2 OR (ToStoreID = 0 AND WorksheetID = 0)) THEN 'Closed'
       WHEN ToStatus = 2 AND (FromStoreID = 0 AND WorksheetID = 0) THEN 'Closed'
       ELSE 'Partial'
    END Status,
    F_ViewInventoryTransferList2.WorksheetID,
    F_ViewInventoryTransferList2.POTitle,
    F_ViewInventoryTransferList2.FromStoreName,
    F_ViewInventoryTransferList2.FromPONumber,
    F_ViewInventoryTransferList2.ToStoreName,
    F_ViewInventoryTransferList2.ToPONumber,
    F_ViewInventoryTransferList2.FromStoreID,
    F_ViewInventoryTransferList2.ToStoreID,
    CASE FromIsPlaced WHEN 0 THEN 'Not placed' WHEN 1 THEN 'Placed' ELSE 'Unknown' END FromPlacementStatus,
    F_ViewInventoryTransferList2.FromDatePlaced,
    CASE ToIsPlaced WHEN 0 THEN 'Not placed' WHEN 1 THEN 'Placed' ELSE 'Unknown' END ToPlacementStatus,
    F_ViewInventoryTransferList2.ToDatePlaced,
    F_ViewInventoryTransferList2.LastUpdated,
    F_ViewInventoryTransferList2.IssueQty,
    F_ViewInventoryTransferList2.IssueValue,
    F_ViewInventoryTransferList2.ReceivedQty,
    F_ViewInventoryTransferList2.ReceivedValue,
    CASE WHEN (ToStoreID = 0 AND WorksheetID = 0) THEN 0
         WHEN (FromStoreID = 0 AND WorksheetID = 0) THEN 0
         ELSE F_ViewInventoryTransferList2.ReceivedQty + F_ViewInventoryTransferList2.IssueQty
  END DiscrepancyQty,
  CASE WHEN (ToStoreID = 0 AND WorksheetID = 0) THEN 0
       WHEN (FromStoreID = 0 AND WorksheetID = 0) THEN 0
       ELSE F_ViewInventoryTransferList2.ReceivedValue + F_ViewInventoryTransferList2.IssueValue
  END Discrepancy
from F_ViewInventoryTransferList2">
</asp:SqlDataSource>

  <dx:ASPxButton ID="ASPxButton1" AutoPostBack="False" runat="server" Text="test" UseSubmitBehavior="False">

      <ClientSideEvents Click="function(s, e) {
    ASPxGridView1.GetSelectedFieldValues('WorksheetID', OnGetSelectedFieldValues);
 }" />
  </dx:ASPxButton>


JavaScript代码:

<script>
    function OnGetSelectedFieldValues(selectedValues) {
        //listBox.ClearItems();
        alert("Workingggg...");
        if (selectedValues.length == 0) return;
        for (i = 0; i < selectedValues.length; i++) {
            s = "";
            for (j = 0; j < selectedValues[i].length; j++) {
                s = s + selectedValues[i][j] + "&nbsp;";
            }
            //listBox.AddItem(s);
            alert(s);
        }
    }
</script>


错误讯息
javascript - 为什么使用ASP.Net在devexpress客户端上不显示选定的行值?-LMLPHP


  即使我尝试在服务器端检索数据,也会引发相同的错误。这是我尝试的服务器端link

最佳答案

该错误是因为您必须指定KeyFieldNameColumn,就像SQL中的PrimaryKey一样,但这是针对DevExpress表的。

根据您的代码,我认为是WorksheetID(但是您可以通过另一个FieldName进行更改),因此您必须更改下一行:

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" Width="100%" SettingsBehavior-AllowSelectByRowClick="True" OnSelectionChanged="btnSearch_Click" KeyFieldName="WorksheetID">

关于javascript - 为什么使用ASP.Net在devexpress客户端上不显示选定的行值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44851776/

10-13 01:43