如何在运行时从Gridview更改自动生成的列的标题文本 [英] how can i change th Header Text of Auto genrated columns from Gridview at run time
本文介绍了如何在运行时从Gridview更改自动生成的列的标题文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我正在使用asp.net 4.0
1.我想删除Gridview中数据库形式自动生成字段的列.
2.如何在运行时从Gridview更改自动生成的列的标题文本
代码:
Hello
i am using asp.net 4.0
1. I want to remove come columns of data base form Auto genrate fields in Gridview.
2. how can i change th Header Text of Auto genrated columns from Gridview at run time
CODE:
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
SqlCommand cmd = new SqlCommand();
cmd.Parameters.Add("@ten", SqlDbType.Float).Value = TextBox1.Text;
cmd.Parameters.Add("@twel", SqlDbType.Float).Value = TextBox2.Text;
cmd.CommandText = "select * from table1 where (ten >= @ten) and (twel >= @twel)";
cmd.Connection = con;
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
GridView1.DataSource = dr;
GridView1.DataBind();
}
}
[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]
[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
推荐答案
不要发布相同的问题两次:它不到5分钟,给人们一个回答的机会,而不是那么急躁!
Don''t post the same question twice: it has been less than 5 minutes, give people a chance to answer, rather than being so impatient!
在回答问题后,请不要删除您的问题!很无礼...
无论如何,对于其他人,这又是解决方案:
使用GridView.HeaderRow属性:
Please don''t delete your questions, when they have been answered! It is very rude...
Anyway, for others, here is the solution again:
Use the GridView.HeaderRow property:
GridViewRow header = gridViewPagedLog.HeaderRow;
header.Cells[0].Text = "Hello";
header.Cells[1].Text = "There";
header.Cells[2].Text = "Mush";
这篇关于如何在运行时从Gridview更改自动生成的列的标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文