使用查询刷新-ASP.Net中的Unbound Gridview [英] Refresh using query - UnBound Gridview in ASP.Net

查看:81
本文介绍了使用查询刷新-ASP.Net中的Unbound Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好团队,

我的页面上有GridView,其中包含以下各列-
Emp_ID,
Emp_Name,
Emp_DOB

我有以下代码来刷新相同的内容-

Hello Team,

I have GridView on my page with following columns -
Emp_ID,
Emp_Name,
Emp_DOB

I have below code to refresh the same-

qry = "SELECT Emp_ID, Emp_Name, Emp_DOB FROM Employee_Master";
SqlCon.Open();
SqlDataAdapter adp = new SqlDataAdapter(qry, SqlCon);
System.Data.DataTable dt = new System.Data.DataTable();
adp.Fill(dt);
GridView1.DataSource = GetData();            
GridView1.DataBind();        
SqlCon.Close();



问题:执行此操作时-它将在GridView中创建新列.
我想要的方式:我只想将数据填充到我在gridview中创建的exesting列中.这将帮助我保持格式,例如字段宽度",自动换行"等.

请帮忙!!



Problem : When I execute this - It will Create New Columns in GridView.
How I Want: I want to populate data to exesting columns only, which I have created in my gridview. This will help me to maintain the formatting such as Field Width, Wrap Text, etc.

Please help!!!!

推荐答案

我想要的方式:我只想将数据填充到在Gridview中创建的Exesting列中.
设置AutoGenerateColumns="false",然后在网格中定义带有预期显示的字段的映射的列.这样,即使数据源具有新字段,也不会影响网格.网格将仅绑定您在列映射中提到的那些字段.

在此处查看列"字段部分: MSDN:GridView类 [^ ]
How I Want: I want to populate data to exesting columns only, which I have created in my gridview.
Set AutoGenerateColumns="false" and then define columns in your grid with mappings to the fields expected to be shown. This way, even if the datasource has new fields it will not affect the grid. Grid will bind only those fields that you have mentioned in your column mappings.

Look at the columns fields section here: MSDN: GridView Class[^]


这篇关于使用查询刷新-ASP.Net中的Unbound Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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