How do I get a copy from a gridview?
I'm trying to get a complete copy of the data from the gridview, itryed clone (), tried casting the DataView from the DataSouce but always gets null values ββor can't get the data, please is there a way to copy the data from the gridview, change it and then reload it? or modifyng directly some rows in the gridview? thanks in advance!
0
source to share
3 answers
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;
}
+1
source to share
Why not just bind the second mesh to the same origin as the first mesh?
DataGridView1.DataSource = yourList;
DataGridView1.DataBind();
...
DataGridView2.DataSource = yourList; //or = DataGridView1.DataSource;
DataGridView2.DataBind();
Until the data has changed, you should get an exact replica.
0
source to share