EDN Admin
Well-known member
Saludos amigos, estoy haaciendo un gridview en el que pueda actuallizar varias filas de una vez.
para ello he puesto un boton en que he puesto el siguiente codigo:
private bool tableCopied = false;
private DataTable originalDataTable;
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
if (!tableCopied)
{
originalDataTable = ((DataRowView)e.Row.DataItem).Row.Table.Copy();
ViewState["originalValuesDataTable"] = originalDataTable;
tableCopied = true;
}
}
protected void btnActualizar_Click(object sender, EventArgs e)
{
originalDataTable = (DataTable)ViewState["originalValuesDataTable"];
foreach (GridViewRow r in GridView1.Rows)
if (IsRowModified(r)) { GridView1.UpdateRow(r.RowIndex, false); }
// Rebind the Grid to repopulate the original values table.
tableCopied = false;
GridView1.DataBind();
}
protected bool IsRowModified(GridViewRow r)
{
int ID;
string valor;
ID = Convert.ToInt32(GridView1.DataKeys[r.RowIndex].Value);
valor = ((TextBox)r.FindControl("txtValor")).Text;
//currentFirstName = ((TextBox)r.FindControl("FirstNameTextBox")).Text;
DataRow row = originalDataTable.Select(String.Format("Id_Hardware = {0}", ID))[0];
if (!valor.Equals(row["Descripcion"].ToString())) { return true; }
//if (!currentFirstName.Equals(row["FirstName"].ToString())) { return true; }
return false;
}
(ESTO LO APRENDI DE UN TUTORIAL)
El problema que tengo es el siguiente:
cuando en el gridview muestro datos de un siple select, me funciona perfectamte, pero cuando el grid muestra datos de un select con joins me tira el error "
Referencia a objeto no establecida como instancia de un objeto."..
y la veradad ya no se que hacer, he probado de varias formas..
espero alguien me pueda ayudar..
Saludos..!!
View the full article
para ello he puesto un boton en que he puesto el siguiente codigo:
private bool tableCopied = false;
private DataTable originalDataTable;
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
if (!tableCopied)
{
originalDataTable = ((DataRowView)e.Row.DataItem).Row.Table.Copy();
ViewState["originalValuesDataTable"] = originalDataTable;
tableCopied = true;
}
}
protected void btnActualizar_Click(object sender, EventArgs e)
{
originalDataTable = (DataTable)ViewState["originalValuesDataTable"];
foreach (GridViewRow r in GridView1.Rows)
if (IsRowModified(r)) { GridView1.UpdateRow(r.RowIndex, false); }
// Rebind the Grid to repopulate the original values table.
tableCopied = false;
GridView1.DataBind();
}
protected bool IsRowModified(GridViewRow r)
{
int ID;
string valor;
ID = Convert.ToInt32(GridView1.DataKeys[r.RowIndex].Value);
valor = ((TextBox)r.FindControl("txtValor")).Text;
//currentFirstName = ((TextBox)r.FindControl("FirstNameTextBox")).Text;
DataRow row = originalDataTable.Select(String.Format("Id_Hardware = {0}", ID))[0];
if (!valor.Equals(row["Descripcion"].ToString())) { return true; }
//if (!currentFirstName.Equals(row["FirstName"].ToString())) { return true; }
return false;
}
(ESTO LO APRENDI DE UN TUTORIAL)
El problema que tengo es el siguiente:
cuando en el gridview muestro datos de un siple select, me funciona perfectamte, pero cuando el grid muestra datos de un select con joins me tira el error "
Referencia a objeto no establecida como instancia de un objeto."..
y la veradad ya no se que hacer, he probado de varias formas..
espero alguien me pueda ayudar..
Saludos..!!
View the full article