如何从 GridPanel 的选定行中获取值? [Ext.Net]

How to get value from selected row of GridPanel? [Ext.Net]

我想访问所选行第一列的值。 我使用 SqlDataSource 作为源,在 Store 中使用 ModelFields。我直接从 sql 数据库获取 GridPanel 的数据。我正在使用 ;

访问所选行的行号
  RowSelectionModel rsm = grid1.SelectionModel.Primary as RowSelectionModel;
  rsm.SelectedIndex.ToString();

并记录 id returns 我没有实现的东西;

  rsm.SelectedRecordID;     //returns ext-33-0 or ext-33-1 depends on row number

如何访问所选行的第一列(或任意一列)?谢谢。

相关脚本;

  <asp:SqlDataSource 
        ID="SqlDataSource1" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:Database %>"
        />
   <ext:Store ID="sqlStore" runat="server" DataSourceID="SqlDataSource1" >


    <Model>
        <ext:Model runat="server">
            <Fields>
                <ext:ModelField Name = "billNo" Unique="true" />
                <ext:ModelField Name = "senderVKN" />
                <ext:ModelField Name = "receiverVKN" />
                <ext:ModelField Name = "Date" Type="Date" />
                <ext:ModelField Name = "Amount" />
            </Fields>
        </ext:Model>
    </Model>
</ext:Store>


  <ext:GridPanel ID="grid1" runat="server"
                AnchorHorizontal="100%"
                AnchorVertical="20%"
                ColumnLines ="true" 
                StoreID ="sqlStore">
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column ID="billColumn" runat="server" Text="Bill No" DataIndex="billNo" ></ext:Column>
                        ...
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single" />
                </SelectionModel>
            </ext:GridPanel>

首先我更改了部分代码;

 <ext:Store ID="sqlStore1" runat="server" DataSourceID="SqlDataSource1" >
    <Model>
        <ext:Model IDProperty="RowID" runat="server" Name="storeModel" >
            <Fields>
                <ext:ModelField Name = "RowID" Type="String"/>
                <ext:ModelField Name = "BillNo" Type="String"/>
                <ext:ModelField Name = "SenderVKN" />
                <ext:ModelField Name = "ReceiverVKN" />
                <ext:ModelField Name = "Date" Type="Date" />
                <ext:ModelField Name = "Amount" />
                <ext:ModelField Name = "Description" />
            </Fields>
        </ext:Model>
    </Model>
</ext:Store>

然后我使用了 RowSelectionModel;

 protected void appBillButton_DirectClick(object sender, DirectEventArgs e)
    {
        RowSelectionModel rsm = grid1.SelectionModel.Primary as RowSelectionModel;
        if (rsm.SelectedRows.Count > 0)
        {
            foreach (SelectedRow sr in rsm.SelectedRows)
            {
                //DoSomeFunction();
            }
            X.Msg.Info("Success", "Function completed successfuly.");
        }
        else
        {
            X.Msg.Alert("Error", "Please select row.").Show();
        }
}

模型字段名称必须与您的 SqlDataSource 的命令值名称相同。