[CLOSED] Checkbox Selected Rows in GridPanel

  1. #1

    [CLOSED] Checkbox Selected Rows in GridPanel

    Hi,

    The following process used to get selected rows [if click on Check Box] from GridPanel in Code Behind. I cant able to get selected rows using this source.

    I will call confirm from code behind to check some validation.
    The following source i have used in ASPX page.
    function Export() {
    GridData.setValue(Ext.encode(GridPanel1.getRowsValues(true, false, false, false)));
    }
    function Confirm() {
    Export();
    btn_confirm.fireEvent('click');
    }
     
    <ext:StoreID="St1"runat="server">
    <Reader>
    <ext:JsonReader>
    <Fields>
    <ext:RecordFieldName="NO">
    </ext:RecordField>
    <ext:RecordFieldName="DESC">
    </ext:RecordField>
    </Fields>
    </ext:JsonReader>
    </Reader>
    </ext:Store>
     
    <ext:GridPanelID="GridPanel1"runat="server"StoreID="St1"StripeRows="true"
    Height="68"Header="false"Width="280"Border="true"AutoScroll="true">
    <ColumnModel>
    <Columns>
    <ext:ColumnDataIndex="NO"Header="No"ColumnID="NO"Hidden="true">
    </ext:Column>
    <ext:ColumnDataIndex="DESC"Header="Kind"ColumnID="DESC"Hidden="false"
    Width="230">
    </ext:Column>
    </Columns>
    </ColumnModel>
    <SelectionModel>
    <ext:CheckboxSelectionModelID="CheckboxSelectionModel1"runat="server">
    </ext:CheckboxSelectionModel>
    </SelectionModel>
     
    </ext:GridPanel>
     
    <ext:ButtonID="btn_confirm"runat="server"Hidden="true">
    <AjaxEvents>
    <ClickOnEvent="BeforeConfirm"ShowWarningOnFailure="false"Timeout="120000">
    </Click>
    </AjaxEvents>
    </ext:Button>
     
    <ext:HiddenID="GridData"runat="server">
    </ext:Hidden>
    The following source i have used in code behind.
    public void BeforeConfirm(object sender, AjaxEventArgs e)
        {
     
                string gridJson = GridData.Value.ToString();
                Dictionary<string, string>[] dic = JSON.Deserialize<Dictionary<string, string>[]>(gridJson);
                string strAdd = string.Empty;
                string strTempNo = string.Empty;
                string strTempDesc = string.Empty;
                foreach (Dictionary<string, string> row in dic)
                {
                    row.TryGetValue("NO", out strTempNo);
                    row.TryGetValue("DESC", out strTempDesc);
                }
    }
    When i use this source to get the value from gridpanel. But It is not working to returns the selected rows.
    Please help me to fix this process
    Last edited by geoffrey.mcgill; Aug 18, 2010 at 5:43 PM. Reason: [CLOSED]
  2. #2
    Hello!

    I can't see where is the Confirm function invoked in your code?
    The code that you provided works fine. Please look at the example based on your code.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Ext.IsAjaxRequest)
            {
                object[] data = new object[]
                {
                    new object[] { "3m Co", 71.72 },
                    new object[] { "Alcoa Inc", 29.01 },
                    new object[] { "Altria Group Inc", 83.81 },
                };
    
                this.Store1.DataSource = data;
                this.Store1.DataBind();
            }
        }
    
        public void BeforeConfirm(object sender, AjaxEventArgs e)
        {
            string gridJson = GridData.Value.ToString();
            Dictionary<string, string>[] dic = JSON.Deserialize<Dictionary<string, string>[]>(gridJson);
            string strAdd = string.Empty;
            string strTempNo = string.Empty;
            string strTempDesc = string.Empty;
            foreach (Dictionary<string, string> row in dic)
            {
                row.TryGetValue("NO", out strTempNo);
                row.TryGetValue("DESC", out strTempDesc);
                Ext.Msg.Alert("BeforeConfirm", strTempNo + " " + strTempDesc).Show();
            }
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    
        <script type="text/javascript">
            function Export() {
                GridData.setValue(Ext.encode(GridPanel1.getRowsValues(true)));
            }
            function Confirm() {
                Export();
                btn_confirm.fireEvent('click');
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ScriptManager runat="server" />
        <ext:Store ID="Store1" runat="server">
            <Reader>
                <ext:ArrayReader>
                    <Fields>
                        <ext:RecordField Name="NO" />
                        <ext:RecordField Name="DESC" />
                    </Fields>
                </ext:ArrayReader>
            </Reader>
        </ext:Store>
        <ext:GridPanel 
            ID="GridPanel1" 
            runat="server" 
            StoreID="Store1" 
            AutoHeight="true">
            <ColumnModel>
                <Columns>
                    <ext:Column DataIndex="NO" Header="No" Hidden="true" />
                    <ext:Column DataIndex="DESC" Header="Kind" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:CheckboxSelectionModel runat="server">
                    <Listeners>
                        <SelectionChange Fn="Confirm"/>
                    </Listeners>
                </ext:CheckboxSelectionModel>
            </SelectionModel>
        </ext:GridPanel>
        <ext:Button ID="btn_confirm" runat="server" Hidden="true">
            <AjaxEvents>
                <Click OnEvent="BeforeConfirm" />
            </AjaxEvents>
        </ext:Button>
        <ext:Hidden ID="GridData" runat="server" />
        </form>
    </body>
    </html>
    Minor issue
    To retrieve selections from GridPanel it's enough to invoke the getRowsValues with only one parameter.
    GridPanel1.getRowsValues(true)
  3. #3

    Checkbox Selected Rows in GridPanel

    Quote Originally Posted by Daniil View Post
    Hello!

    I can't see where is the Confirm function invoked in your code?
    The code that you provided works fine. Please look at the example based on your code.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <%@ Import Namespace="System.Collections.Generic" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Ext.IsAjaxRequest)
            {
                object[] data = new object[]
                {
                    new object[] { "3m Co", 71.72 },
                    new object[] { "Alcoa Inc", 29.01 },
                    new object[] { "Altria Group Inc", 83.81 },
                };
     
                this.Store1.DataSource = data;
                this.Store1.DataBind();
            }
        }
     
        public void BeforeConfirm(object sender, AjaxEventArgs e)
        {
            string gridJson = GridData.Value.ToString();
            Dictionary<string, string>[] dic = JSON.Deserialize<Dictionary<string, string>[]>(gridJson);
            string strAdd = string.Empty;
            string strTempNo = string.Empty;
            string strTempDesc = string.Empty;
            foreach (Dictionary<string, string> row in dic)
            {
                row.TryGetValue("NO", out strTempNo);
                row.TryGetValue("DESC", out strTempDesc);
                Ext.Msg.Alert("BeforeConfirm", strTempNo + " " + strTempDesc).Show();
            }
        }
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
     
        <script type="text/javascript">
            function Export() {
                GridData.setValue(Ext.encode(GridPanel1.getRowsValues(true)));
            }
            function Confirm() {
                Export();
                btn_confirm.fireEvent('click');
            }
        </script>
     
    </head>
    <body>
        <form runat="server">
        <ext:ScriptManager runat="server" />
        <ext:Store ID="Store1" runat="server">
            <Reader>
                <ext:ArrayReader>
                    <Fields>
                        <ext:RecordField Name="NO" />
                        <ext:RecordField Name="DESC" />
                    </Fields>
                </ext:ArrayReader>
            </Reader>
        </ext:Store>
        <ext:GridPanel 
            ID="GridPanel1" 
            runat="server" 
            StoreID="Store1" 
            AutoHeight="true">
            <ColumnModel>
                <Columns>
                    <ext:Column DataIndex="NO" Header="No" Hidden="true" />
                    <ext:Column DataIndex="DESC" Header="Kind" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:CheckboxSelectionModel runat="server">
                    <Listeners>
                        <SelectionChange Fn="Confirm"/>
                    </Listeners>
                </ext:CheckboxSelectionModel>
            </SelectionModel>
        </ext:GridPanel>
        <ext:Button ID="btn_confirm" runat="server" Hidden="true">
            <AjaxEvents>
                <Click OnEvent="BeforeConfirm" />
            </AjaxEvents>
        </ext:Button>
        <ext:Hidden ID="GridData" runat="server" />
        </form>
    </body>
    </html>
    Minor issue
    To retrieve selections from GridPanel it's enough to invoke the getRowsValues with only one parameter.
    GridPanel1.getRowsValues(true)
    Hi,

    Thank you.
    I have used extra params when click on the button.
    It has working fine.
  4. #4

    Helps

    Hi speedstepmem4

    Can you put your Code Source with ExraParam Please

    thinks

Similar Threads

  1. [CLOSED] How to get selected rows count in gridpanel
    By egvt in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 31, 2012, 5:22 PM
  2. Replies: 1
    Last Post: Oct 13, 2010, 11:09 PM
  3. [CLOSED] How to set all rows as selected in GridPanel
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 30, 2010, 4:42 PM
  4. Replies: 2
    Last Post: Dec 25, 2009, 2:56 PM
  5. [CLOSED] Get selected rows in GridPanel
    By danielg in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 24, 2009, 12:48 PM

Tags for this Thread

Posting Permissions