如何从 GridPanel 的选定行中获取值? [外网]
Posted
技术标签:
【中文标题】如何从 GridPanel 的选定行中获取值? [外网]【英文标题】:How to get value from selected row of GridPanel? [Ext.Net] 【发布时间】:2015-06-17 11:04:10 【问题描述】:我想访问所选行的第一列的值。 我使用 SqlDataSource 作为源,并在 Store 中使用 ModelFields。我直接从 sql 数据库中获取了 GridPanel 的数据。我正在使用 ;
访问所选行的行号 RowSelectionModel rsm = grid1.SelectionModel.Primary as RowSelectionModel;
rsm.SelectedIndex.ToString();
并且记录 id 返回一些我没有实现的东西;
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>
【问题讨论】:
【参考方案1】:首先我更改了我的代码的某些部分;
<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 的命令值名称相同。
【讨论】:
以上是关于如何从 GridPanel 的选定行中获取值? [外网]的主要内容,如果未能解决你的问题,请参考以下文章