用“city”替换城市的名称。 [英] Replace the name of the cities with "city"
本文介绍了用“city”替换城市的名称。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从SQL Server中检索数据到ASP.Net中的网格视图。下面是从数据库中检索数据后网格视图的标题。
I am retrieving data from SQL Server to a grid view in ASP.Net. Below is the header of the grid view after I retrieved the data from the database.
Time| Atlanta_1| Atlanta_2| Atlanta_3|
我想动态地用城市替换城市名称,例如
I want to replace the name of the cities with "City" dynamically e.g.
Time| City_1| City_2| City_3|
所以基本上我想用City替换标题的一部分,我想在网格视图中绑定它而不是在SQL Server中。下面是我如何从数据库中检索数据到我的gridview的代码
我尝试过:
So basically I want to replace a part of the header with "City" and I want to do it while binding it in a grid view NOT in SQL Server. Below is the code how I am retrieving data from the database to my gridview
What I have tried:
SqlConnection con = new SqlConnection("My Connection");
string s = "My Stored Procedure"
con.Open();
SqlDataAdapter da = new SqlDataAdapter(s,con);
DataSet ds = new DataSet();
da.Fill(ds);
gridView1.DataSource = ds;
gridView1.DataBind();
con.Close();
推荐答案
可以在绑定之前更改DataTable中的列名:
could change the column names inside the DataTable before binding:
var ds = GetDataSet();
foreach(DataColumn col in ds.Tables[0].Columns)
{
col.ColumnName = col.ColumnName.Replace("Atlanta_", "City_");
}
gridView1.DataSource = ds;
gridView1.DataBind();
这篇关于用“city”替换城市的名称。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文