tags:

views:

1895

answers:

4

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!

A: 

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.

Phil Corcoran
A: 

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.

p.campbell
when i set to viewstate = false , it dissapears when users clicks in the second aux gridview
Angel Escobedo
+1  A: 

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;
}
dragonjujo
Im using RowCommand
Angel Escobedo
is possible to use that working with TemplateFields? i get a button and another column for checkbox
Angel Escobedo
For RowCommand, you'll have to do some sort of data retrieval from the lists you used to populate the GridView
dragonjujo
If I'm getting the right idea from your comments and posts, then I have a working version of what you want, in a sense, but you should have most of what you need to work out the solution yourself in the answer here.
dragonjujo
A: 

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.

Ricardo Villamil
Im doing like it so check please:IList<DetalleCita> testDetail = scvCitas.GetDetalleCosto(codeCarta, codigoEstudio, codeAseguradora, rucAseguradora); dgvEstudios.DataSource = testDetail; dgvEstudios.DataBind();
Angel Escobedo
and im getting null when i try to get the datasource property from a gridview instance
Angel Escobedo