Hello
I would like to know how to add a row to a webdatagrid in c # and add data from a table or view. Earlier in UltraWebDataGrid was this:
void Llenartabla(DataView mivista) { this.MiDatagrid.Rows.Clear(); UltraGridRow mifila= new UltraGridRow(); this.MiDatagrid.Rows.Add(row);
mifila.Cells.FromKey("Dia").Text = (mivista.Table.Columns.Contains("DiaP"))? mivista[0]["DiaP"].ToString(); mifila.Cells.FromKey("Horario").Text = (mivista.Table.Columns.Contains("HorarioP"))? mivista[0]["HorarioP"].ToString(); mifila.Cells.FromKey("Tipo").Text = "Pago"; }
In advance thank you very much
Hello,
Adding a row directly to the grid is not possible in code behind. You need to add the row to the grid dataSource and dataBind the grid to the updated data. Please let me know what dataSource you use to populate the grid and I will suggest accordingly.
If you use DataTable then this is a sample code to add row to a table with three columns("id", "Item" and "Data"):
protected void WebDataGrid1_RowAdding(object sender, Infragistics.Web.UI.GridControls.RowAddingEventArgs e) { DataTable table = (DataTable)Session["data"]; var row = table.NewRow(); row["id"] = e.Values["id"]; row["Item"] = e.Values["Item"]; row["Data"] = e.Values["Data"]; table.Rows.Add(row); table.AcceptChanges();
Session["data"] = table;
this.WebDataGrid1.DataSource = table; this.WebDataGrid1.DataBind(); }
You can also refer to this resources for more examples on manual RowAdding in WebDataGrid:
http://www.infragistics.com/community/blogs/developer_support/archive/2012/02/03/webdatagrid-manual-crud.aspx
https://www.youtube.com/watch?v=VxGoBSTvG7c
Please let me know if you have further questions on this matter.
thanks very much, really it was more easy with a DataTable, this worked, you do not want to lose the method that was used ... but I got the data as wanted ..