This is a migrated thread and some comments may be shown as answers.

Add row get value problem

3 Answers 57 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chang
Top achievements
Rank 1
Chang asked on 12 Oct 2015, 01:13 PM

Hi, I am new to Telerik and am currently developing a program for my company. I click on the "Click here to add a new row" button on the top and input the values for each column. Then I want to have the user press a "save" button and save these values to the Oracle database. I am unable to get the values for each column. I've came across many versions of this problem throughout my search, but I want the most up to date one that would allow me to get the new row values that I entered from "Click here to add a new row". Thanks! Both dr and currentRow.value return null.

 private void btSave_Click(object sender, EventArgs e)
        {
            GridViewRowInfo dr = this.gvUser.GridViewElement.CurrentRow as GridViewRowInfo;
            GridViewNewRowInfo currentRow = dr as GridViewNewRowInfo; 
            
            if (currentRow != null)
            {
                string test = dr.Cells[1].Value.ToString();

                 test = currentRow.Cells[1].Valiue.Tostring();
                 test = dr.Cells[2].Value.ToString();
                 test = dr.Cells[3].Value.ToString();
                 test = dr.Cells[4].Value.ToString();
                 test = dr.Cells[5].Value.ToString();
            }
        }

3 Answers, 1 is accepted

Sort by
0
Chang
Top achievements
Rank 1
answered on 13 Oct 2015, 01:39 AM
I played around with it a bit more. So it seems I can't do anything with the values like with default value until I hit enter and have the values committed to the bottom rows.
0
Chang
Top achievements
Rank 1
answered on 13 Oct 2015, 03:40 AM
New question, how do I loop through the collection of rows at the bottom from "click here to add a new row"? I want to loop through them so I can add all of them into the database at once.
0
Accepted
Dimitar
Telerik team
answered on 13 Oct 2015, 08:49 AM
Hi Chang,

Thank you for writing.

In the first case, the row is already added to the grid and it is the last row so you can access it like this:
private void radButton1_Click(object sender, EventArgs e)
{
    var row = radGridView1.Rows[radGridView1.Rows.Count - 1];
}

Another approach would be to use the new row events. Detailed information is available here: New Row. As a general solution, you should consider using the RowsChanged event which will fire when something is changed in the grid. This way you will be able to update the database: Tracking changes in RadGridView.

The following article show how you can iterate all rows in the grid: Iterating Rows.

I hope this will be useful. 

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Chang
Top achievements
Rank 1
Answers by
Chang
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or