Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my application I am using a gridview in that lots of columns are there. I am binding the gridview with the datatble values. Now I like to update the datatable with the modified gridview values. In the datatable I am having the selectid=N and Y. I am binding only the SelectId=Y values into the grid. Now my question is I want to update the datatable with the updated values in the gridview for the selectid=Y in the datatable.

Thanks in Advance
Posted
Updated 25-Nov-11 21:22pm
v2

hi,

I) If your grid bind with database directly.

You should bind with Edit Temple of Grid and on Edit_Command(...) event find
datakeys value and updated database values and bind again.
Check condition also.


II) if your grid view bind runtime dataTable.

First Bind Grid with datatable. Fill datatable values in new DataTable or
ViewState or Session .
now on the basis of Grid datakeys values updatae New DataTable values and again fill first datable and bind again.
 
Share this answer
 
v2
Comments
RaviRanjanKr 26-Nov-11 3:40am    
Nice Answer! My 5+
Niranjankr 26-Nov-11 3:56am    
Thank's..
hi
You can use following code

protected void girdview_selectedindexchange(..

{

DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Age");
DataRow dataRow;
dataRow = dt.NewRow();
int i2 = 1;
for (int i = 0; i < dataRow.Table.Columns.Count; i++)
{ 
dataRow[i] = GridView1.SelectedRow.Cells[i2].Text;
i2++;
}

dt.Rows.Add(dataRow);

lit_NewDataTable.Text = "New DataTable in a DataGrid:<br />";
DataGrid1.DataSource = dt;
DataGrid1.DataBind();

}
 
Share this answer
 
v2
Comments
RaviRanjanKr 26-Nov-11 3:42am    
A suggestion :- Always wrap your code in "Pre" tag. it gives better readability to other users.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900