How to get values from grid panel selected row

  1. #1

    How to get values from grid panel selected row

    Dear Forum Members


    Please tell me "HOW TO GET VALUES FROM GRID PANEL SELECTED ROW USING CODE BEHIND IN VB.NET".
  2. #2
    Hi,

    Here is the example:
    https://examples1.ext.net/#/GridPane...itting_Values/

    It's on C#. If you will be in trouble to convert it to VB, I can suggest to look a C# to VB converter up on the internet.
  3. #3

    VIsual Basic Code for that example is enlisted below

    Quote Originally Posted by Daniil View Post
    Hi,

    Here is the example:
    https://examples1.ext.net/#/GridPane...itting_Values/

    It's on C#. If you will be in trouble to convert it to VB, I can suggest to look a C# to VB converter up on the internet.

    Visual Basic Code

    Protected Sub Row_Click(ByVal sender As Object, ByVal e As DirectEventArgs)
            Dim Id As String = Nothing
            Dim js As String = e.ExtraParams("Values")
            If String.IsNullOrEmpty(js) Then
                Exit Sub
            End If
            Dim xml As XmlNode = JSON.DeserializeXmlNode("{records:{record:" + js + "}}")
            'for each row as XmlNode in xml.SelectNodes("records/record"))
            For Each row As XmlNode In xml.SelectNodes("records/record")
                Id = row.SelectSingleNode("ID").InnerXml
            Next
            FillCntrls(Id)
        End Sub
    Last edited by Daniil; Apr 09, 2012 at 2:58 PM. Reason: Please use [CODE] tags
  4. #4
    Hi, Daniil

    could show me where I'm wrong?
     <asp:WizardStep ID="wSelWorkshops" runat="server" StepType="Step" 
                        Title="Selecionar Workshops">
                        
                        <ext:Store ID="Store1" runat="server" GroupField="inicio">
                            <Reader>
                                <ext:JsonReader>
                                    <Fields>
                                        <ext:RecordField Name="idturma" />
                                        <ext:RecordField Name="inicio" />
                                        <ext:RecordField Name="horaini" />
                                        <ext:RecordField Name="horafim" />
                                        <ext:RecordField Name="etp_Etapa" />
                                        <ext:RecordField Name="Educador" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                        <ext:GridPanel 
                                ID="GridPanelWS"
                                runat="server"
                                StoreID="Store1"
                                StripeRows="true"
                                Title="Worskops"
                                Collapsible="true"
                                AutoExpandColumn="inicio" 
                                Width="650"
                                Height="550"
                                Frame="true">
                                <ColumnModel runat="server" ID="ctlWS">
                                    <Columns>
                                    <ext:Column runat="server" ColumnID="ID" Header="" DataIndex="idturma" MenuDisabled="true" Fixed="true" Resizable="false" Width="0"/>
                                    <ext:DateColumn runat="server" Width="75" DataIndex="inicio"  Header="Data" Format="dd/MM/yy"  />
                                    <ext:DateColumn runat="server" Width="45" DataIndex="horaini" Header="Inicio" Format="H:mm" />
                                    <ext:DateColumn runat="server" Width="45" DataIndex="horafim" Header="Inicio" Format="H:mm" />
                                    <ext:Column runat="server" ColumnID="etp_Etapa" Width="250" DataIndex="etp_Etapa" Header="Atividade" />
                                    <ext:Column runat="server" ColumnID="etp_Etapa" Width="150" DataIndex="Educador" Header="Palestrante" />
                                </Columns>
                            </ColumnModel>
                             <LoadMask ShowMask="true" />
                           <SelectionModel>
                           <ext:CheckboxSelectionModel runat="server" ID="csmWS" />
                       
                           </SelectionModel>
                           <View>
                           <ext:GroupingView
                                ID="gpvWS"
                                HideGroupedColumn="true"
                                runat="server"
                                Forcefit="true"
                                GroupTextTpl='{text}'
                                EnableRowBody="true">
                                <GetRowClass Handler="var d = record.data; rowParams.body = String.format('<div style=\'padding:0 5px 5px 5px; \'></div>', d.idturma,d.horaini,d.horafim,d.etp_Etapa,d.Educador);" />
    
    <Templates>
    <Header Visible="False" ID="ctl3" runat="server"></Header>
    </Templates>
                                </ext:GroupingView>
                           </View>
                           <Buttons>
                           <ext:Button ID="btnWS" runat="server" Text="Prosseguir" Visible="true">
                           <DirectEvents>
                                <Click OnEvent="bntWS_Click">
                                    <ExtraParams>
                                    <ext:Parameter Name="Values" Value="Ext.encode(#{gpvWS}.getRowsValues({selectedOnly: true}))" Mode="Raw" />
                                    </ExtraParams>
                                    <EventMask ShowMask="true" />
                                </Click>
                           </DirectEvents>
                           </ext:Button>
                           </Buttons>
                        </ext:GridPanel>
                    </asp:WizardStep>
     protected void bntWS_Click(object sender, DirectEventArgs e) {
                var values = JSON.Deserialize<Dictionary<string, string>>(e.ExtraParams["values"]);
                StringBuilder sb = new StringBuilder();
                foreach (var value in values) {
                    sb.AppendFormat("{0}={1}<br/>", value.Key, value.Value);
                    }
                X.Msg.Alert("Values", sb.ToString()).Show();
               
            }
    Quote Originally Posted by Daniil View Post
    Hi,

    Here is the example:
    https://examples1.ext.net/#/GridPane...itting_Values/

    It's on C#. If you will be in trouble to convert it to VB, I can suggest to look a C# to VB converter up on the internet.
  5. #5
    Hi @Madson,

    Please provide more details about the problem.
  6. #6
    First was not able to run the event to read the grid.
    I could do it.
    Now, is not returning the values ​​selected.

    I'm following the examples:
    https://examples1.ext.net/#/GridPane...itting_Values/
    https://examples1.ext.net/#/GridPane...box_Selection/

    Quote Originally Posted by Daniil View Post
    Hi @Madson,

    Please provide more details about the problem.
  7. #7
    Please provide a full example to run locally and reproduce the problem.
  8. #8
    Quote Originally Posted by Daniil View Post
    Please provide a full example to run locally and reproduce the problem.
    This is the aspx code:
      <ext:Store ID="Store1" runat="server" GroupField="inicio">
                            <Reader>
                                <ext:JsonReader>
                                    <Fields>
                                        <ext:RecordField Name="idturma" />
                                        <ext:RecordField Name="inicio" />
                                        <ext:RecordField Name="horaini" />
                                        <ext:RecordField Name="horafim" />
                                        <ext:RecordField Name="etp_Etapa" />
                                        <ext:RecordField Name="Educador" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                        <ext:GridPanel 
                                ID="GridPanelWS"
                                runat="server"
                                StoreID="Store1"
                                StripeRows="true"
                                Title="Worskops"
                                Collapsible="true"
                                AutoExpandColumn="inicio" 
                                Width="650"
                                Height="550"
                                Frame="true">
                                <ColumnModel runat="server" ID="ctlWS">
                                    <Columns>
                                    <ext:Column runat="server" ColumnID="ID" Header="" DataIndex="idturma" MenuDisabled="true" Fixed="true" Resizable="false" Width="0"/>
                                    <ext:DateColumn runat="server" Width="75" DataIndex="inicio"  Header="Data" Format="dd/MM/yy"  />
                                    <ext:DateColumn runat="server" Width="45" DataIndex="horaini" Header="Inicio" Format="H:mm" />
                                    <ext:DateColumn runat="server" Width="45" DataIndex="horafim" Header="Inicio" Format="H:mm" />
                                    <ext:Column runat="server" ColumnID="etp_Etapa" Width="250" DataIndex="etp_Etapa" Header="Atividade" />
                                    <ext:Column runat="server" ColumnID="etp_Etapa" Width="150" DataIndex="Educador" Header="Palestrante" />
                                </Columns>
                            </ColumnModel>
                             <LoadMask ShowMask="true" />
                           <SelectionModel>
                                    <ext:CheckboxSelectionModel runat="server" ID="csmWS" />
                           </SelectionModel>
                           <View>
                           <ext:GroupingView
                                ID="gpvWS"
                                HideGroupedColumn="true"
                                runat="server"
                                Forcefit="true"
                                GroupTextTpl='{text}'
                                EnableRowBody="true">
                                <Templates>
                                    <Header Visible="False" ID="ctl3" runat="server"></Header>
                                </Templates>
                                </ext:GroupingView>
                           </View>
                           <Buttons>
                           <ext:Button ID="btnWS" runat="server" Text="Prosseguir" Visible="true">
                           <DirectEvents>
                                <Click OnEvent="bntWS_Click">
                                   <EventMask ShowMask="true" />                               
                                </Click>
                           </DirectEvents>
                           </ext:Button>
                           </Buttons>
                        </ext:GridPanel>
    this is the code in the code chsarp
     protected void bntWS_Click(object sender, DirectEventArgs e)
            {
                string json = e.ExtraParams["Values"];
                if (string.IsNullOrEmpty(json))
                {
                    return;
                }
                Dictionary<string, string>[] lst = JSON.Deserialize<Dictionary<string, string>[]>(json);
                foreach (Dictionary<string, string> row in lst) { 
                    
                    int id = Convert.ToInt32(row["idturma"]);
                    DateTime inicio = Convert.ToDateTime(row["inicio"]);
                    DateTime horaini = Convert.ToDateTime(row["horaini"]);
                    DateTime horafim = Convert.ToDateTime(row["horafim"]);
                    string etapa = row["etp_Etapa"];
                    string educador = row["educador"];
                }
    
                X.Msg.Alert("Workshops selecionados", lst.Length.ToString());
                
    
            }
    Is is view
    Click image for larger version. 

Name:	Capturar.PNG 
Views:	321 
Size:	60.6 KB 
ID:	4090
  9. #9
    I think there resolved, was not passing the parameter:

    <ext:Parameter Name="Values" Value="Ext.encode(#{GridPanelWS}.getRowsValues({selectedOnly: true}))" Mode="Raw" />
    Inspecting, I can see the values, but does not go to a messagebox or label, the value is not displayed.

    New Code
     <ext:Store ID="Store1" runat="server" GroupField="inicio">
                            <Reader>
                                <ext:JsonReader>
                                    <Fields>
                                        <ext:RecordField Name="idturma" />
                                        <ext:RecordField Name="inicio" />
                                        <ext:RecordField Name="horaini" />
                                        <ext:RecordField Name="horafim" />
                                        <ext:RecordField Name="etp_Etapa" />
                                        <ext:RecordField Name="Educador" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                        <ext:GridPanel 
                                ID="GridPanelWS"
                                runat="server"
                                StoreID="Store1"
                                StripeRows="true"
                                Title="Worskops"
                                Collapsible="true"
                                AutoExpandColumn="inicio" 
                                Width="650"
                                Height="550"
                                >
                                <ColumnModel runat="server" ID="ctlWS">
                                    <Columns>
                                    <ext:Column runat="server" ColumnID="ID" Header="" DataIndex="idturma" MenuDisabled="true" Fixed="true" Resizable="false" Width="0"/>
                                    <ext:DateColumn runat="server" Width="75" DataIndex="inicio"  Header="Data" Format="dd/MM/yy"  />
                                    <ext:DateColumn runat="server" Width="45" DataIndex="horaini" Header="Inicio" Format="H:mm" />
                                    <ext:DateColumn runat="server" Width="45" DataIndex="horafim" Header="Inicio" Format="H:mm" />
                                    <ext:Column runat="server" ColumnID="etp_Etapa" Width="250" DataIndex="etp_Etapa" Header="Atividade" />
                                    <ext:Column runat="server" ColumnID="etp_Etapa" Width="150" DataIndex="Educador" Header="Palestrante" />
                                </Columns>
                            </ColumnModel>
                             <LoadMask ShowMask="true" />
                           <SelectionModel>
                                    <ext:CheckboxSelectionModel runat="server" ID="csmWS" />
                           </SelectionModel>
                           <View>
                           <ext:GroupingView
                                ID="gpvWS"
                                HideGroupedColumn="true"
                                runat="server"
                                Forcefit="true"
                                GroupTextTpl='{text}'
                                EnableRowBody="true">
                                <Templates>
                                    <Header Visible="False" ID="ctl3" runat="server"></Header>
                                </Templates>
                                </ext:GroupingView>
                           </View>
                           <Buttons>
                           <ext:Button ID="btnWS" runat="server" Text="Prosseguir" Visible="true">
                           <DirectEvents>
                                <Click OnEvent="bntWS_Click">
                                  <ExtraParams>
                                    <ext:Parameter Name="Values" Value="Ext.encode(#{GridPanelWS}.getRowsValues({selectedOnly: true}))" Mode="Raw" />
                                    </ExtraParams>
                                   <EventMask ShowMask="true" />                               
                                </Click>
                           </DirectEvents>
                           </ext:Button>
                           </Buttons>
                        </ext:GridPanel>
    
                        <div style="width:590px; height:100px; border:1px solid gray; padding:5px;">
                <ext:Label ID="Label1" runat="server" />
    Code Behind
     string json = e.ExtraParams["Values"];
                if (string.IsNullOrEmpty(json))
                {
                    return;
                }
                Dictionary<string, string>[] lst = JSON.Deserialize<Dictionary<string, string>[]>(json);
                foreach (Dictionary<string, string> row in lst)
                {
    
                    int id = Convert.ToInt32(row["idturma"]);
                    DateTime inicio = Convert.ToDateTime(row["inicio"]);
                    DateTime horaini = Convert.ToDateTime(row["horaini"]);
                    DateTime horafim = Convert.ToDateTime(row["horafim"]);
                    string etapa = row["etp_Etapa"];
                    string educador = row["Educador"];
                }
                resultado(lst.Length);
            }
            protected void resultado(int result) {
                this.Label1.Html = "</br></br>" + result.ToString() + "</br></br>";
            }
    Last edited by Daniil; Apr 11, 2012 at 12:04 PM. Reason: Please use [CODE] tags for all code
  10. #10
    At the first glance the piece of the code you posted is correct.

    Please provide a full example which we could run without any changes and reproduce the problem.

Similar Threads

  1. Replies: 1
    Last Post: Mar 11, 2012, 3:03 AM
  2. Editable Grid Panel Cells Values
    By garag in forum 1.x Help
    Replies: 0
    Last Post: Sep 20, 2011, 3:29 PM
  3. Replies: 3
    Last Post: Jun 03, 2011, 12:10 PM
  4. How to get selected values form grid in code behind
    By harshad.jadhav in forum 1.x Help
    Replies: 1
    Last Post: Jul 12, 2010, 8:51 AM
  5. [CLOSED] Getting selected row and values in Grid
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: May 28, 2009, 8:04 AM

Tags for this Thread

Posting Permissions