如何更新gridview中的数据 [英] How to update data in gridview
本文介绍了如何更新gridview中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下拉列表中有一份员工列表。
我在数据库中有员工表。
如果用户从下拉列表中选择员工我在gridview中绑定了所选emp的数据。
现在我想更新gridview中特定所选用户的信息,如何更新
解决方案
嗨。只需将以下代码添加到您的应用程序,即可在下拉列表的索引更改事件中更新数据gridview。
void UpdateGrid()
{
// 打开连接
using (SqlCeConnection c = new SqlCeConnection( ConnectionString))
{
c.Open();
// 2
/ / 使用创建新的DataAdapter
(SqlCeDataAdapter a = new SqlCeDataAdapter( SELECT * FROM table WHERE empID = + EmpId,c))
{
// 3
< span class =code-comment> // 使用DataAdapter填充DataTable
DataTable t = new DataTable();
a.Fill(t);
// 4
/ / 将数据渲染到屏幕上
dataGridView1.DataSource = t;
}
}
}
如果您有任何问题,请退回..
很多例子都在 Google [ ^ ]和 CodeProject [ ^ ]。我认为你需要在发布之前搜索更多内容。
更多:
在GridView中编辑基础数据 [ ^ ]
Gridview编辑ASP.NET中的删除和更新 [ ^ ]
Asp.Net GridView - 如何在c#.net 中更新GridView中的删除插入[ ^ ]
插入更新删除在Asp.net中显示Gridview数据示例 [ ^ ]
Gridview插入更新删除在asp .net [ ^ ]
I have a list of employees in dropdownlist.
I have employee table in database.
if user select an employee from dropdown am binding data of that selected emp in gridview.
Now i wants to update the info of the particular selected user in gridview,How can i update
解决方案
Hi . Just add following code to your application to Update data gridview on index changed event of drop down list.
void UpdateGrid() { // Open connection using (SqlCeConnection c = new SqlCeConnection("ConnectionString")) { c.Open(); // 2 // Create new DataAdapter using (SqlCeDataAdapter a = new SqlCeDataAdapter("SELECT * FROM table WHERE empID="+EmpId, c)) { // 3 // Use DataAdapter to fill DataTable DataTable t = new DataTable(); a.Fill(t); // 4 // Render data onto the screen dataGridView1.DataSource = t; } } }
Kindly revert if you have any issues..
Tons of example there in Google[^] and CodeProject[^]. I think you need to search more before posting this.
More:
Editing the Underlying Data in a GridView[^]
Gridview Edit Delete and Update in ASP.NET[^]
Asp.Net GridView – How to Update Delete Insert in GridView in c#.net[^]
Insert Update Delete Show Gridview Data Example in Asp.net[^]
Gridview insert update delete in asp .net[^]
这篇关于如何更新gridview中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文