PDA

View Full Version : [CLOSED] Get multiple RecordID from GridPanel



Mario
Nov 30, 2014, 6:15 PM
I need to get RecordID from GridPanel rows selected... but only the IDProperty field.

My code:



<ext:GridPanel runat="server" ID="GridPanelRisultato" MarginSpec="2 0 0 0" Flex="1" Border="true">
<Store>
<ext:Store runat="server" ID="StoreRisultato">
<Model>
<ext:Model runat="server" IDProperty="CodiceUtente">
<Fields>
<ext:ModelField Name="CodiceTipoUtente" Type="String" />
<ext:ModelField Name="CodiceUtente" Type="String" />
<ext:ModelField Name="Cognome" Type="String" />
<ext:ModelField Name="Nome" Type="String" />
<ext:ModelField Name="RagioneSociale" Type="String" />
<ext:ModelField Name="Stato" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server" EnableColumnHide="False">
<Columns>
<ext:ComponentColumn runat="server" DataIndex="CodiceTipoUtente" Width="22">
<Component>
<ext:Image runat="server" Height="20"/>
</Component>
<Listeners>
<BeforeBind Handler="e.config[0].imageUrl = Ext.net.ResourceMgr.resolveUrl(Ext.String.format(' ~/Immagini/{0}.png', e.record.data.CodiceTipoUtente));" />
</Listeners>
</ext:ComponentColumn>
<ext:Column runat="server" Text="CodiceUtente" DataIndex="CodiceUtente" Width="100"/>
<ext:Column runat="server" Text="Cognome" DataIndex="Cognome" Width="100"/>
<ext:Column runat="server" Text="Nome" DataIndex="Nome" Width="100"/>
<ext:Column runat="server" Text="RagioneSociale" DataIndex="RagioneSociale" Flex="1"/>
<ext:Column runat="server" Text="Stato" DataIndex="Stato" Width="100"/>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel runat="server" Mode="Multi" >
<DirectEvents>
<Select OnEvent="RowSelection_Event" />
</DirectEvents>
</ext:RowSelectionModel>
</SelectionModel>
<Plugins>
<ext:FilterHeader runat="server" />
</Plugins>
</ext:GridPanel>




Protected Sub RowSelection_Event(sender As Object, e As Ext.Net.DirectEventArgs)
Dim Selezione As Ext.Net.RowSelectionModel = TryCast(GridPanelRisultato.GetSelectionModel(), Ext.Net.RowSelectionModel)

Dim Elenco As New StringBuilder()

For Each Riga As Ext.Net.SelectedRow In Selezione.SelectedRows
Elenco.AppendFormat("RecordID: {0} ", Riga.RecordID)
Next

End Sub


If I select two rows, the RowSelectionModel return zero rows !

Help please

Daniil
Dec 01, 2014, 2:09 PM
Hi Mario,

It appears to be working for me. If I select two rows, it shows "2" for me. Please try the example. Does it work correctly to you? If yes, please provide your full test case that doesn't work.

Example

<%@ Page Language="C#" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new object[] { "test", "test" },
new object[] { "test", "test" },
new object[] { "test", "test" }
};
}
}

protected void RowSelectionModel_Select(object sender, DirectEventArgs e)
{
X.Msg.Alert("RowSelectionModel_Select", (GridPanel1.GetSelectionModel() as RowSelectionModel).SelectedRows.Count).Show();
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:GridPanel ID="GridPanel1" runat="server">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test1" />
<ext:ModelField Name="test2" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test 1" DataIndex="test1" />
<ext:Column runat="server" Text="Test 2" DataIndex="test2" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel runat="server" Mode="Multi">
<DirectEvents>
<Select OnEvent="RowSelectionModel_Select" />
</DirectEvents>
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>
</form>
</body>
</html>

Mario
Dec 02, 2014, 4:55 AM
If you run the example in a UserControl not works !


WebForm1.aspx


<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">

<ext:ResourceManager runat="server" />

<ext:Viewport runat="server">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Center" />
</LayoutConfig>

<Items>
<ext:Panel ID="PanelApplicazione" runat="server" Flex="1" Width="1000" Border="false" PaddingSpec="5 0 5 0" Layout="FitLayout" />
</Items>

</ext:Viewport>

</form>
</body>
</html>


WebForm1.aspx.vb


Public Class WebForm1
Inherits System.Web.UI.Page

Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim Applicazione As New Ext.Net.UserControlLoader
Applicazione.Path = "WebUserControl1.ascx"
PanelApplicazione.Items.Clear()
PanelApplicazione.Items.Add(Applicazione)
End Sub

End Class


WebUserControl1.ascx


<%@ Control Language="vb" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.vb" Inherits="WebApplication2.WebUserControl1" %>

<ext:GridPanel ID="GridPanel1" runat="server">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test1" />
<ext:ModelField Name="test2" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test 1" DataIndex="test1" />
<ext:Column runat="server" Text="Test 2" DataIndex="test2" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel runat="server" Mode="Multi">
<DirectEvents>
<Select OnEvent="RowSelectionModel_Select" />
</DirectEvents>
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>


WebUserControl1.ascx.vb


Public Class WebUserControl1
Inherits System.Web.UI.UserControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Ext.Net.X.IsAjaxRequest Then
Dim store As Ext.Net.Store = Me.GridPanel1.GetStore()
store.DataSource = New Object() {New Object() {"test", "test"}, New Object() {"test", "test"}, New Object() {"test", "test"}}
End If
End Sub

Protected Sub RowSelectionModel_Select(sender As Object, e As Ext.Net.DirectEventArgs)
Ext.Net.X.Msg.Alert("RowSelectionModel_Select", TryCast(GridPanel1.GetSelectionModel(), Ext.Net.RowSelectionModel).SelectedRows.Count).Sho w()
End Sub

End Class

Daniil
Dec 03, 2014, 11:21 AM
Please replace "Page_Load" with "Page_Load". It should start working.

I would also recommend to set explicit IDs.

For the user control:

Applicazione.UserControlID = "WebUserControl1"

For the RowSelectionModel also.

<ext:RowSelectionModel ID="RowSelectionModel1" runat="server">

Mario
Dec 03, 2014, 12:16 PM
Danill,

you wrote...



Please replace "Page_Load" with "Page_Load"


What ?
:)

Daniil
Dec 03, 2014, 12:22 PM
Sorry. Page_Load with Page_Init.

Mario
Dec 03, 2014, 1:04 PM
I have replaced "Page_Load" with "Page_Init"...
and assigned an ID valid to Objects...
but not works... :(

Danill, please can you try to run my code and test on it?
Very very tnx !

mario

Daniil
Dec 03, 2014, 2:14 PM
Yes, actually I tried my suggestion before suggesting it to you. The only thing that I needed to get your code working is replacing "Page_Load" with "Page_Init".

Mario
Dec 03, 2014, 3:22 PM
I am distraught !

In this location:

http://dropcanvas.com/aw79o

there is a ZIP file with the complete solution of the test with all the files and settings (except EXT.NET bin files)
Can you try on this code ?

Tnx

Daniil
Dec 03, 2014, 6:24 PM
Sorry, I was not clear enough. Please replace Page_Load with Page_Init in the page, not in the user control.

Mario
Dec 03, 2014, 7:12 PM
Tnx danill !!!
It's perfect.

:)