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

时间:2022-12-03 10:05:06

I wanna access value of first column of selected row. I used SqlDataSource as a source, and ModelFields in Store. I got datas for GridPanel directly from sql database. I am accessing row number of selected rows by using ;

我想访问所选行的第一列的值。我使用SqlDataSource作为源,并使用Store中的ModelFields。我直接从sql数据库获得了GridPanel的数据。我通过使用访问所选行的行号;

  RowSelectionModel rsm = grid1.SelectionModel.Primary as RowSelectionModel;
  rsm.SelectedIndex.ToString();

and record id returns something that i did not implement;

和记录id返回我没有实现的东西;

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

How can I access the first (or any) column of selected row? Thank you.

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

Related scripts;

相关脚本;

  <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>

1 个解决方案

#1


0  

First of all I changed some parts of my code;

首先,我更改了代码的某些部分;

 <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>

then I used RowSelectionModel;

然后我用了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();
        }
}

Model field names must be same with your SqlDataSource's command value names.

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

#1


0  

First of all I changed some parts of my code;

首先,我更改了代码的某些部分;

 <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>

then I used RowSelectionModel;

然后我用了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();
        }
}

Model field names must be same with your SqlDataSource's command value names.

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