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


What exactly are you trying to do with the data? Also, is it a datagrid or dataview and in what framework? If it is the datagrid you are trying to copy rows from, loop over the datagrid rows and add the row values ​​to the arraylist.



0


source


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







All Articles