如何将网格的值插入数据表 [英] How to insert the values of grid into the datatable

查看:56
本文介绍了如何将网格的值插入数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的应用程序中,我使用的是gridview,因为那里有很多列.我将gridview与datatble值绑定在一起.现在,我想用修改后的gridview值更新数据表.在数据表中,我有selectid=N 和Y.我仅将SelectId=Y values绑定到网格中.现在我的问题是我想使用数据表中selectid=Y的gridview中的更新值来更新数据表.

在此先感谢

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

推荐答案



I)如果您的网格直接与数据库绑定.

您应该绑定编辑网格之殿",并在Edit_Command(...)事件上找到
datakeys值和更新的数据库值,然后再次绑定.
还要检查条件.


II)如果您的网格视图绑定了运行时dataTable.

第一个具有数据表的绑定网格.在新的DataTable或
中填充datatable值 ViewState或Session.
现在基于Grid数据键值updatae New DataTable值,并再次填充第一个datable并再次绑定.


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.


hi
您可以使用以下代码

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();

}


这篇关于如何将网格的值插入数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆