在代码视图中写入datagrid标头文本 [英] write datagrid header text in code view
本文介绍了在代码视图中写入datagrid标头文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生,
在我的Web应用程序中,我将Excel数据显示给Datagrid.工作正常.
datagrid单元格标题文本显示为Excel工作表的列名称
数据.
但我的目标是我想为我的数据网格单元格标题文本显示其他名称.
我的代码是:
hi sir,
in my web app i am display Excel data to Datagrid. its working fine.
datagrid cells header text is displayed column names of Excel sheet
data.
but my aim is i want to display other names for my datagrid cells Header Text.
my code is:
String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Book2.xls;" +
"Extended Properties=Excel 8.0;";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter
("SELECT * FROM [Sheet1$]", strConn);
da.Fill(ds);
DataGrid2.DataSource = ds.Tables[0].DefaultView;
DataGrid2.DataBind();
请给我一个解决办法
please give me a solution
Thanks.
推荐答案
,strConn); da.Fill(ds); DataGrid2.DataSource = ds.Tables [0] .DefaultView; DataGrid2.DataBind();
", strConn); da.Fill(ds); DataGrid2.DataSource = ds.Tables[0].DefaultView; DataGrid2.DataBind();
请给我一个解决办法
谢谢.
please give me a solution
Thanks.
在gridview中添加您想要的标题的列,并在声明select语句时使用AS子句提及与垂直字段相关的标题
(例如,选择"student_name"作为名称)
然后绑定数据源
Add the columns in gridview with the headers u want and while stating select statement mention the headers associated with perticular field with AS clause
(example select student_name as name)
and then bind datasource
您还可以使用 ^ ]更改标题的文本.
检查链接以了解更多详细信息.
You can also use DataGridColumn.HeaderText Property[^] to change the text of the header.
Check the link for more details.
这篇关于在代码视图中写入datagrid标头文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文