iam autogenerating the columns in the webdatagrid and want to add a new empty row in the WebDatagrid with server side by pressing a button.
The new row should be added at the bottom of the WebDatagrid .
In order to add a new empty row in the WebDataGrid you have to execute the following code in the button click event handler. Note that if the WebDataGrid has a primaryKey set, you can’t leave the respective field empty.
private void AddRow(object sender, EventArgs e)
DataRow row = (WebDataGrid1.DataSource as DataTable).NewRow();
//row["id"] = (WebDataGrid1.DataSource as DataTable).Rows.Count + 1;
(WebDataGrid1.DataSource as DataTable).Rows.Add(row);
You can find additional information about the row adding in this topic.
Thank you for using our product, if you have any further questions please contact me!
it worked but i need to select the new row after adding it ; i used :
var lenght = WebDataGrid1.Rows.Count;
SelectedRowCollection selectedRows = this.WebDataGrid1.Behaviors.Selection.SelectedRows; selectedRows.Add(this.WebDataGrid1.Rows[lenght]);
but this didn't work. i want to select the new row and active any cell after adding it.
what am i doing wrong ?
I'm currently investigating how to properly add the row to selected rows collection using server side code. I'll send you a sample demonstrating the required approach tomorrow.
thank you i'll wait
Here you will find a sample where a new empty row is added at the bottom of the WebDataGrid on "Add Row Server Side" button click. The newly added row will be auto selected. This happens in the AddRow() method which is the server side click handler of the button.