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.
Syncfusion Feedback

button click event reading all rows from datagrid

Thread ID:

Created:

Updated:

Platform:

Replies:

120788 Oct 15,2015 04:21 AM UTC Oct 20,2015 04:42 AM UTC ASP.NET Web Forms 5
loading
Tags: Grid
Pratheep
Asked On October 15, 2015 04:21 AM UTC


Hi

It's possible button click event read each and every row, column and cells in a Grid and get its value


protected void btnSave_Click(object sender, EventArgs e)
{
   
foreach(GridViewRow row in Grid.Rows)
{
    for(int i = 0; i < Grid.Columns.Count; i++)
    {
        String header = Grid.Columns[i].HeaderText;
        String cellText = row.Cells[i].Text;
    }
}

}

Thanks
Pratheep

Saravanan Arunachalam [Syncfusion]
Replied On October 16, 2015 10:23 AM UTC

Hi Pratheep,

We have achieved your requirement using server side OnClick event of Button control and read the row, column and cell value using DataSource and Column property of the Grid control on server side. Please refer to the following code example.

[aspx]

<ej:Button ID="ButtonNormal" runat="server" Size="Large" OnClick="ClearButton_Click" ShowRoundedCorner="true" Text="Button"></ej:Button>


[aspx.cs]

protected void ClearButton_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)

        {

            var gridModel = this.OrdersGrid;

            foreach (EditableOrder gridData in (dynamic)gridModel.DataSource)

            {

                foreach (Syncfusion.JavaScript.Models.Column gridCol in (dynamic)gridModel.Columns)

                {

                    object cellText =gridData.GetType().GetProperty(gridCol.Field).GetValue(gridData, null);

                    string header = gridCol.HeaderText;

                  

                }

            }

        }



We have created the sample that can be downloaded from the below link:

http://www.syncfusion.com/downloads/support/forum/120788/ze/AspGrid-2024568733

Regards,

Saravanan A.


Pratheep
Replied On October 16, 2015 01:19 PM UTC

Hi

Thanks for guidance

here showing  error  - Cannot convert type 'DialogEditing.WebForm1.Orders' to 'MVCSampleBrowser.Models.EditableOrder'

Without EditableOrder class it's possible can get cellText


Thanks

Pratheep


Attachment: Inline_Editing_9eeff546.rar

Saravanan Arunachalam [Syncfusion]
Replied On October 19, 2015 10:33 AM UTC

Hi Pratheep,

In our previous sample, we have used EditableOrder as view-model class for binding datasource to the Grid. 

In your sample, we found that you have bound the datasource to the Grid using Orders class but have mentioned EditableOrder inside the button click event which is the cause of the issue. To resolve the issue, replace EditableOrder Class with Orders Class as in the following code example.

protected void ClearButton_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)

        {

            . . .

            //Orders view-model class instead of EditableOrder

            foreach (Orders gridData in (dynamic)gridModel.DataSource)

            {

                . . .

            }

        }


We have modified your sample with the above solution, which can be downloaded from the below link:

http://www.syncfusion.com/downloads/support/forum/120788/ze/F120788877347764

Regards,

Saravanan A.


Pratheep
Replied On October 19, 2015 08:41 PM UTC

Hi

Thanks ..it's working fine 

Pratheep

Saravanan Arunachalam [Syncfusion]
Replied On October 20, 2015 04:42 AM UTC

Hi Pratheep,

Thanks for your update.

We are happy to hear that your issue has been resolved.

Please get back us if you need any further assistance. We will happy to assist you.

Regards,

Saravanan A.


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.

Warning Icon 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.Close Icon

;