We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Selected row

Thread ID:

Created:

Updated:

Platform:

Replies:

121627 Jan 10,2016 02:09 PM Jan 18,2016 08:46 AM ASP.NET Web Forms 5
loading
Tags: Grid
Manuel Santos
Asked On January 10, 2016 02:09 PM

I am trying to use the content of a selected row in a function on the .cs, but I can't find a way. Can you please help me?
I have a grid and a button, and when I press the button, I want to had a record to a table different from the one that feeds the grid.

            <ej:grid runat='server' ID="sgEmCurso" DataSourceCachingMode="None" MinWidth="0" AllowPaging="True" BackColor="Red" BorderColor="Black" ForeColor="White">
                <ClientSideEvents RowSelected="rowSelected" />
                <Columns>
                    <ej:Column Field="IDProjecto" Visible="False">
                    </ej:Column>
                    <ej:Column Field="NomeProjecto" HeaderText="Nome Projecto">
                    </ej:Column>
                    <ej:Column Field="NomeArtigo" HeaderText="Nome Artigo">
                    </ej:Column>
                    <ej:Column Field="DataAbertura" Format="{0:dd/MM/yyyy}" HeaderText="Data Abertura">
                    </ej:Column>
                    <ej:Column Field="DescricaoTipoProjecto" HeaderText="Tipo Projecto">
                    </ej:Column>
                </Columns>
                <PageSettings Template=""></PageSettings>
                <ScrollSettings EnableTouchScroll="False"></ScrollSettings>
        </ej:grid>


        protected void sbtButton_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
        {
            var grid = sgEmCurso;

        }


Sellappandi Ramu [Syncfusion]
Replied On January 11, 2016 02:23 AM

Hi Manuel,

Thanks for contacting Syncfusion support.

While using button sever click event, we can get the button model in server side can’t get the grid model. So we need to pass the selected records before trigger the server side click event. We suggest you to use Ajax method in clientsideonclick event to get the selected records in server side.

Please refer to the code example and sample,

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">

    <ej:button id="ButtonNormal" runat="server" type="Button" clientsideonclick="Click" size="Normal" text="Click"></ej:button>

    <ej:grid id="FlatGrid" runat="server" allowpaging="True">

        <Columns>

               <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="Right" Width="90">                  

               </ej:Column>

               <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="90">                  

               </ej:Column>              

               <ej:Column Field="EmployeeID" HeaderText="Employee ID" Width="110"></ej:Column>

               <ej:Column Field="ShipCity" HeaderText="ShipCity" Width="90" />

            </Columns>

         <PageSettings Template="" ></PageSettings>

    </ej:grid>

    <script type="text/javascript">

        function Click(element) {

            var gridObj = $("#<%=FlatGrid.ClientID%>").ejGrid("instance");

            if (gridObj.getSelectedRecords().length != 0) {

                var customerID = gridObj.getSelectedRecords()[0];

                $.ajax({

                    url: "/Default.aspx/Data",

                    type: "POST",

                    contentType: "application/json; charset=utf-8",

                    dataType: "json",

                    data: JSON.stringify({ data: customerID }),

                    success: function (data) {

                        alert(data.d);

                    }

                })

            }

            else

                alert("No record selected")

        }
    </script>
[Aspx.cs]

[System.Web.Services.WebMethod]

        public static object Data(Orders data)

        {

            //perform operation

            return "";// return the data
        }


Sample: http://www.syncfusion.com/downloads/support/forum/121627/ze/Sample_121627680167393

Refer to the online help documentation for getSelectedRecords(),

Document: http://help.syncfusion.com/js/api/ejgrid#methods:getselectedrecords


Screen shot to get the selected records in server side.



Regards,
Sellappandi R

Manuel Santos
Replied On January 11, 2016 04:32 AM

As you might see in the code I sent, I have an hiden cell, which is the first one. Is it possible to use it's content?

Mohammed Farook J [Syncfusion]
Replied On January 12, 2016 04:18 AM

Hi Manuel,

The getSelectedRecords() method of the Grid returns all the data including the hidden columns. Please find the code example.

<ej:grid id="FlatGrid" runat="server" allowpaging="True">

        <Columns>

               <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="Right" Width="90">                  

               </ej:Column>

               <ej:Column Field="CustomerID" Visible="false" HeaderText="Customer ID" Width="90">                  

               </ej:Column>             

                   . . .

    </ej:grid>

    <script type="text/javascript">

        function Click(element) {

            var gridObj = $("#<%=FlatGrid.ClientID%>").ejGrid("instance");

            if (gridObj.getSelectedRecords().length != 0) {

                var customerID = gridObj.getSelectedRecords()[0];

                $.ajax({

                    url: "/Default.aspx/Data",

                    type: "POST",

                    contentType: "application/json; charset=utf-8",

                    dataType: "json",

                    data: JSON.stringify({ data: customerID }),

                    success: function (data) {

                        alert(data.d);

                    }

                })

            }

            else

                alert("No record selected")

        }
    </script>

[Aspx.cs]

        [System.Web.Services.WebMethod]

        public static object Data(Orders data)

        {

            //perform operation

            return "";// return the data
        }



For your convenience we have prepared a sample that can be downloaded from the following  link:
Sample: http://www.syncfusion.com/downloads/support/directtrac/149498/ze/Sample1827275800

Refer to the  screen shot to get the selected records in server side:




Please let us know if you have any queries.
Regards,
J.Mohammed Farook

Manuel Santos
Replied On January 15, 2016 09:40 PM

Isn't there any other way? I need to use in the c# function the value of some textboxes and I don't find a way to get those values.

Mohammed Farook J [Syncfusion]
Replied On January 18, 2016 08:46 AM

Hi Manuel,

Based on your request we have created a sample and it can be downloaded from the following link:

Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample2109893463.zip


Please find the code snippet.

[aspx]

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">

   <asp:TextBox id="cus_input" runat="server"></asp:TextBox>

    <ej:button id="ButtonNormal" runat="server" type="Button" clientsideonclick="Click" size="Normal" text="Click"></ej:button>

    <ej:grid id="FlatGrid" runat="server" allowpaging="True">

        <Columns>

               . . .

            </Columns>

         . . .

    </ej:grid>

    <script type="text/javascript">

        function Click(element) {

            var gridObj = $("#<%=FlatGrid.ClientID%>").ejGrid("instance");

            if (gridObj.getSelectedRecords().length != 0) {

               

                var customerID = gridObj.getSelectedRecords()[0];

               

                customerID.textValue = $('#<%= cus_input.ClientID %>').val();

                $.ajax({

                    url: "/Default.aspx/Data",

                    type: "POST",

                    contentType: "application/json; charset=utf-8",

                    dataType: "json",

                    data: JSON.stringify({ data: customerID }),

                    success: function (data) {

                        alert(data.d);

                    }

                })

            }

            else

               alert("No record selected")

        }

    </script>
</asp:Content>

[aspx.cs]

   public static object Data(Object data)

        {

            //perform operation

            return "";// return the data
        }



In above sample we create “asp text box” in this sample.  We have append the textbox value to getSelectedRecord() array. Please find the code snippet.


                var customerID = gridObj.getSelectedRecords()[0];

               

                customerID.textValue = $('#<%= cus_input.ClientID %>').val();





Please refers the screen shot:


Regards,
J.Mohammed Farook




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;