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
close icon

button click event reading all rows from datagrid


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

5 Replies

SA Saravanan Arunachalam Syncfusion Team 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.



PR Pratheep 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


SA Saravanan Arunachalam Syncfusion Team 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.



PR Pratheep October 19, 2015 08:41 PM UTC

Hi

Thanks ..it's working fine 

Pratheep


SA Saravanan Arunachalam Syncfusion Team 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.


Loader.
Live Chat Icon For mobile
Up arrow icon