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. Image for the cookie policy date

Accessing each row

Hi,

I have a little problem, I need to access to each row of the Grid because I need to change the background color of the row depending of the register. In the native Control of Visual Studio is like this:

foreach(GridViewRow row in GridView1.Rows){

   row[i] = ….

}

I tried to find a method but I couldn’t, please help me if you know the answer.

Thanks.


8 Replies

RU Ragavee U S Syncfusion Team May 4, 2015 07:10 AM UTC

Hi Julio,

Thanks for your interest in Syncfusion Products.

We are glad to let you know that we have an event “rowDataBound” in grid which is triggered every time a request is made to access any row information.

Please refer the below Class reference link for more information on the rowDataBound event.

Class Reference Link: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#event:rowDataBound

For your convenience, we have created a simple sample and the sample can be downloaded from the below location.

Sample Link: http://www.syncfusion.com/downloads/support/forum/118987/Sample-1814495003.zip

In the above sample, we have changed the background color of the row depending on the data present in the row. Please refer the below code snippets.

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


<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="true" >

<ClientSideEvents RowDataBound="rowDataBound" />

. . . . . .

</ej:Grid>



<script type="text/javascript">

function rowDataBound(args) {

if (args.data.EmployeeID % 3 == 0)

args.row.css("backgroundColor", "yellow").css("color", "red");/*custom css applied to the row */

}

</script>
</asp:Content>


Please try the sample and get back to us if you need any further assistance.

Regards
Ragavee U S


PB Parag Bagga August 7, 2016 10:15 AM UTC

Hi can you please tell me how to hande row data bound event server side


PB Parag Bagga August 7, 2016 10:16 AM UTC

how can we iterate row by row in ej grid on server side aspx page. please help!


RU Ragavee U S Syncfusion Team August 8, 2016 06:17 AM UTC

Hi Parag, 

We have achieved your requirement to have server side event for RowDataBound event using the PageMethods mechanism. The PageMethods acts similar to that of the jquery AJAX call. Please refer the below link for more information on pagemethods. 


For your convenience, we have created a simple sample using PageMethods and the same can be downloaded from the below location. 


In the above sample we have passed event arguments using “PageMethods” in “RowDataBound” client side event of the grid as follows. 
Site.Master 
<%--Enable PagerMethods--%> 
<asp:ScriptManager runat="server" EnablePageMethods="true"> 
</asp:ScriptManager> 
 
Default.aspx 
<ej:Grid ID="FlatGrid" runat="server" AllowSorting="True" AllowPaging="True">
         <ClientSideEvents RowDataBound="rowDataBound" />
. . . . 
</ej:Grid> 
<script type="text/javascript"> 
        function rowDataBound(args) { 
//PageMethods object to call the WebMethod of the page. 
            PageMethods.OnRowDataBound(args.data); //passing the required parameters to the server side method 
        } 
    </script> 

Default.aspx.cs 
[WebMethod] 
        public static void OnRowDataBound(object sender) 
        { 
            //code to perform custom operation 
        } 

Regards, 
Ragavee U S. 



AA Avishake Attari October 18, 2016 05:18 AM UTC

Hi,

how to use this [WebMethod] (i.e. server side rowDataBound Event) to change the data depending on some condition in ej grid on server side aspx.cs page. 


please help!


RU Ragavee U S Syncfusion Team October 19, 2016 09:15 AM UTC

Hi Avishake, 

We don’t have server side events for control rendering related actions. If you would like to change the text of a cell based on certain condition, then we suggest you to use the queryCellInfo client side event of the grid.  

Please refer to the below links for more information. 



Regards, 
Ragavee U S. 



AA Avishake Attari October 25, 2016 11:38 AM UTC

Thanks Ragavee U S [Syncfusion]

I was able to use queryCellInfo event and change the way the data binds to my grid.

Now I have a requirement where I need to open a popup on click of an unbound button
and in that popup I need TextBoxes that are bound with the records in the syncfusion gird row
so that I can update the fields on click of button in the popup.



Regards
Avishake Attari



RU Ragavee U S Syncfusion Team October 26, 2016 10:37 AM UTC

Hi Avishake, 

We analyzed your requirement to update the record on Command button click. We can achieve this using the inbuilt options supported by Command column feature of the Grid. Please refer to the below online links for more information. 



As you would like to edit the grid records within a dialog, we can achieve it using the Dialog Edit mode of the Grid. Please refer to the below documentation for information on the various edit modes supported by Grid control. 


We have prepared a sample based on your request, which can be downloaded from the below location. 


Regards, 
Ragavee U S. 


Loader.
Live Chat Icon For mobile
Up arrow icon