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

ASP.GRID <ej:Grid CHANGE HEADER TEXT AFTER DATABOUND

Hi I 'm have an issue here.
I want to change header text of grid columns after the data bound is complete.
My grid has dynamic columns via data source each time and so auto generated columns.
So i need to have the grid after the data bound and render events in order to change header text according other datasource.
Something like the server event rowdatabound of the asp grid view.
Also ,
I'm trying to save the grid values after after button submit .How can i iterate over rows
Regards
Nikos

3 Replies

VA Venkatesh Ayothi Raman Syncfusion Team March 17, 2016 11:44 AM UTC

Hi Nikos,

Thanks for contacting Syncfusion support.

Query 1:”Change the HeaderText after databound”
We have achieved your requirement “change the header text name” using dataBound event and created a sample. Please refer to the code example, documentation and sample,

Code example:

<ej:Grid ID="Grid1"  AllowSorting="true" AllowPaging="True"

             AllowScrolling="True" AllowResizing="True" 

            EnableRowHover="true" 

              AllowReordering="false" Locale="en-US" AllowMultiSorting="false"

             AllowGrouping="True" 

            runat="server">         

             <PageSettings PageSize="15" />         

          

             <ClientSideEvents ToolbarClick="onToolBarClick" DataBound="dataBound"/>

        </ej:Grid>

<code something>

function dataBound(args) {


       

        this.model.columns[0]['headerText'] = "Modified headerText name";


        this.columns(args.model.columns);

    }



Sample:HTchangeinDBevent


Help documentation:http://help.syncfusion.com/js/api/ejgrid#methods:columns

Query 2:”Save the grid values after button submit”
Please share the following details, it would be helpful for us to provide the better solution as earliest,
1)      Edit mode that you are using?
2)      Do you want insert or update a record through server side? Or Unable to perform server side operation to update a record?
3)      Do you want access the row data using server side event?
4)       Code example.


Regards,
Venkatesh Ayothiraman.


NI NiKOS March 17, 2016 12:02 PM UTC

HI Venkatesh Ayothiraman.

Thank you for your quick reply.
Query 1:”Change the HeaderText after databound”
Can i do it this  Server side???
I have to change the grid.columns.HeadersText according data from Database table.

Query 2:”Save the grid values after button submit”
Please share the following details, it would be helpful for us to provide the better solution as earliest,
1)      Edit mode that you are using?
       Batch 
2)      Do you want insert or update a record through server side? Or Unable to perform server side operation to update a record? 
        Yes . No
3)      Do you want access the row data using server side event?
        i want to access row data using server side event.

Basically , 
I want to save all the values the user will have enter at the grid server side by iterate the grid .
So  I need besides grid.columns to have the rows? in order to get from all the cells the value and then save it to specific data tables

Regards
Nikos


VA Venkatesh Ayothi Raman Syncfusion Team March 18, 2016 01:22 PM UTC

Hi Nikos,

Thanks for your update.

Query 1:”Can I do this server side?”
Yes, you can change the header text in server side using onDataBound server side event. Please refer to the below code example,

<aspx.cs page>

public void Databound(object sender, System.EventArgs e)

        {

            this.Grid1.Columns[0].HeaderText = "Modify";

        }



Query 2:”Save the grid values in server side”
We have achieved your requirement using server side event onServerBatchEditRow and get the updated values from event arguments. We get a modified value as arrayList, we need to convert the array to our corresponding instance when we edit, delete or insert a record from client side. So, now you are able to save the values into the datasource. For your convenience, we have created a sample and refer to the code example,
Code example:

public void batchChanges(object sender, GridEventArgs e) {


           

            Orders ord = new Orders();           

           BatchChanges batch = new BatchChanges();


            ArrayList changed = ((ArrayList)((Dictionary<String, Object>)e.Arguments["batchChanges"])["changed"]);


            ArrayList added = ((ArrayList)((Dictionary<String, Object>)e.Arguments["batchChanges"])["added"]);


            ArrayList deleted = ((ArrayList)((Dictionary<String, Object>)e.Arguments["batchChanges"])["deleted"]);

            foreach (Dictionary<string, object> source in changed)

                 batch.changed.Add(ObjectExtensions.ToObject<Orders>(source));

            foreach(Dictionary<string, object> source in added)

                batch.added.Add(ObjectExtensions.ToObject<Orders>(source));

            foreach (Dictionary<string, object> source in deleted)

                batch.deleted.Add(ObjectExtensions.ToObject<Orders>(source));

<Code something>

public static class ObjectExtensions

    {

        public static T ToObject<T>(this Dictionary<string, object> source)

        where T : class, new()

            {

            T someObject = new T();

            Type someObjectType = someObject.GetType();


            foreach (KeyValuePair<string, object> item in source)

            {

                someObjectType.GetProperty(item.Key).SetValue(someObject, item.Value, null);

            }


            return someObject;

        }

    }

 
Sample:SyncfusionASPNETApplication2


Regards,
Venkatesh Ayothiraman.

Loader.
Live Chat Icon For mobile
Up arrow icon