动态绑定网格视图 [英] Dynamically binding grid view
本文介绍了动态绑定网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在单击按钮时动态绑定了Grid视图.但是问题在于,如果我再次按下按钮,则会显示重复数据.
例如.
按钮单击
abc xzy
1 1
2 1
再次单击按钮
按钮单击
abc xzy abc xzy
1 1 1 1
2 1 2 1
请帮忙.
Hi,
I am dynamically binding the Grid view on button click. But the problem is that if I again press on the button the duplicate data displays.
for ex.
button click
abc xzy
1 1
2 1
again button click
button click
abc xzy abc xzy
1 1 1 1
2 1 2 1
Please help.
DataTable GetBatchDetail = new DataTable();
GetBatchDetail = objAdmin.abc(FromDate, Todate, cityid, Type);
foreach (DataColumn col in GetBatchDetail.Columns)
{
BoundField bField = new BoundField();
bField.DataField = col.ColumnName;
bField.HeaderText = col.ColumnName;
GridView1.Columns.Add(bField);
}
GridView1.DataSource = GetBatchDetail;
//Bind the datatable with the GridView.
GridView1.DataBind();
推荐答案
尝试在代码之前添加此代码:
Try to add this code before your code :
//It will clear old DataBindings
dataGridView1.DataBindings.Clear
dataGridView1.Columns.Clear();
希望对您有所帮助:)
I hope it will help you :)
Add this line in ur code
Add this line in ur code
GridView1.Columns.Clear();
Replace ur code
Replace ur code
DataTable GetBatchDetail = new DataTable();
GetBatchDetail = objAdmin.abc(FromDate, Todate, cityid, Type);
GridView1.Columns.Clear();
foreach (DataColumn col in GetBatchDetail.Columns)
{
BoundField bField = new BoundField();
bField.DataField = col.ColumnName;
bField.HeaderText = col.ColumnName;
GridView1.Columns.Add(bField);
}
GridView1.DataSource = GetBatchDetail;
GridView1.DataBind();
这篇关于动态绑定网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文