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.

Write to SQL database

Thread ID:

Created:

Updated:

Platform:

Replies:

118467 Mar 10,2015 04:54 PM Mar 11,2015 01:35 AM ASP.NET Web Forms 1
loading
Tags: Grid
peterV
Asked On March 10, 2015 04:54 PM

I placed the Grid to web page (.aspx). In a context I setup AllowEditing, AllowSorting a and created DataSource for Select,, Update, Insert.
When is page in running, all is correct. I can  edit cells but it is just in grid. It haven't affect in database.

<ej:Grid ID="Grid1" runat='server' DataMember="DefaultView" DataSourceID="SqlDataSource1" MinWidth="0" AllowSorting="True">

<Columns>

<ej:Column DataType="string" Field="Name" HeaderText="MENO" >
<NumericEditOptions Tag="" />
</ej:Column>

<ej:Column DataType="number" Field="Age" HeaderText="VEK" >
<NumericEditOptions Tag="" />
</ej:Column>

<ej:Column DataType="number" Field="Temp" HeaderText="TEMP" >
<NumericEditOptions Tag="" />
</ej:Column>

<ej:Column AllowEditing="False" DataType="number" Field="id" HeaderText="ID" IsIdentity="True" IsPrimaryKey="True" >
<NumericEditOptions Tag="" />
</ej:Column>

</Columns>

<PageSettings Template=""></PageSettings>
<EditSettings AllowEditing="True" />

</ej:Grid>

Thanks
Peter



Ajith R [Syncfusion]
Replied On March 11, 2015 01:35 AM

Hi Peter,

Thanks for using Syncfusion products.

Query: I can  edit cells but it is just in grid. It haven't affect in database.

We suggest you to use server side edit events (OnServerEditRow, OnServerAddRow, OnServerDeleteRow) and apply the edit changes from Grid to SQL database by using SQL commands to achieve your requirement. We can get the event arguments from the GridEventArgs class and perform edit operation based on its eventType. Please refer the below code snippet for further details.


[aspx]

    <ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlData"

        OnServerEditRow="EditEvents_ServerEditRow" OnServerAddRow="EditEvents_ServerAddRow" OnServerDeleteRow="EditEvents_ServerDeleteRow" MinWidth="0">

        ------

        ------

    </ej:Grid>   

[cs]

// Server side update record

    protected void EditEvents_ServerEditRow(object sender, GridEventArgs e)

    {

        EditAction(e.EventType, e.Arguments["data"]);

    }

    //Server side add record

    protected void EditEvents_ServerAddRow(object sender, GridEventArgs e)

    {

        EditAction(e.EventType, e.Arguments["data"]);

    }

    // Server side delete record

    protected void EditEvents_ServerDeleteRow(object sender, GridEventArgs e)

    {

        EditAction(e.EventType, e.Arguments["data"]);

    }

    protected void EditAction(string eventType, object record)

    {

        Dictionary<string, object> KeyVal = record as Dictionary<string, object>;

        if (eventType == "endEdit")

        {

            -------

            -------

        }

        else if (eventType == "endAdd")

        {

            --------

            --------

        }

        else if (eventType == "endDelete")

        {

            -------

            -------

        }

        this.OrdersGrid.DataBind();

    }

 

Please refer the below online demo for further details.

Online Demo: http://asp.syncfusion.com/demos/web/grid/sqlbinding.aspx

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

Sample Link: http://www.syncfusion.com/downloads/support/directtrac/118467/SQLDataGrid305565162.zip

Please let us know if you have any concerns.

Regards,

Ajith R



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.

;