Hi Folks, Im trying to get a completly data copy from a gridview, itryed clone(), tryed cast DataView from DataSouce, but always get nulls or cant get the data, please exists a way to copy data from gridview, modified it and then reload it? or modifyng directly some rows in the gridview? thanks in advance!
What exactly is it you're trying to do with the data? Also is it a datagrid or a dataview and in what framework? If it's a datagrid that you're trying to copy the rows from,loop through the datagrid rows and add the row values to an arraylist.
Do you have viewstate=false on the grid?
What kind of datasource are you using? ListOf, SqlDataSource, ObjectDataSource, etc?
Perhaps make a copy of your datasource into a local variable before it is databound.
(ugly: Try saving it into viewstate or session).
Try a foreach on the gridview.rows after you've bound the data.
You can try using the OnRowDataBound attribute to do something like this
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//HeaderStuff
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
ObjectTye objectType = (ObjectType)e.Row.DataItem;
// and doing some stuff with the properties
e.Row.Cells[0].Text = objectType.SomeProperty.ToString();
LinkButton deleteLnk = (LinkButton)e.Row.FindControl("lnkDelete");
deleteLnk.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this')");
deleteLnk.CommandArgument = e.Row.RowIndex.ToString();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = int.Parse(e.CommandArgument.ToString());
GridViewRow row = GridView1.Rows[rowIndex];
ObjectType objectType = new ObjectType();
objectType.StringProperty = row.Cells[0].Text;
}
Why not just bind the second grid the same source the first grid is bound to?
DataGridView1.DataSource = yourList;
DataGridView1.DataBind();
...
DataGridView2.DataSource = yourList; //or = DataGridView1.DataSource;
DataGridView2.DataBind();
As long as the data hasn't changed your should get an exact replica.