如何动态创建gridview的标题? [英] How To create Header of gridview dynamically?

查看:79
本文介绍了如何动态创建gridview的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Helo朋友,

如何在运行时动态创建gridview的标题?

i已经在我的.cs文件上写了一些代码,但我不知道在我的文件中写些什么.aspx file..please helpme。

提前致谢。

解决方案

HI,



这是一个链接,它解释了带有标题的动态网格创建请检查这个。



带标题的动态gridview



谢谢


In。 cs文件,你使用sql查询gridview数据源,如

 选择 id,name,email 来自 tablename 





默认情况下,如果要更改,查询列名称是gridview标题它然后你可以使用查询



 选择 id  ID,名称 [客户名称],电子邮件 电子邮件来自 tablename 







请不要忘记将它标记为ans如果你得到它的帮助

谢谢

Hemant Singh


你的问题很混乱。你说你已经在.cs文件中写了一些代码但是不知道在.aspx文件中写什么?标题建议您想要动态创建gridview的标题。对于该位,请尝试以下代码:

  protected   void  GridView1_RowCreated( object  sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView grd =(GridView)sender;

GridViewRow HeaderRow = new GridViewRow(-1,-1,DataControlRowType.Header,DataControlRowState.Insert);

TableCell HeaderCell = new TableCell();
HeaderCell.Text = 第一列;
HeaderCell.Style [ font-weight] = bold;
HeaderRow.Cells.Add(HeaderCell);

HeaderCell = new TableCell();
HeaderCell.Text = 第二列;
HeaderCell.Style [ font-weight] = bold;
HeaderRow.Cells.Add(HeaderCell);

HeaderCell = new TableCell();
HeaderCell.Text = 第三栏;
HeaderCell.Style [ font-weight] = bold;
HeaderRow.Cells.Add(HeaderCell);

grd.Controls [ 0 ]。Controls.AddAt( 0 ,HeaderRow );
}
}





对于除此之外的任何其他要求,请编辑您的问题并重新发布。


Helo friends,
How to create header of gridview dynamically at runtime?
i have written some code on my .cs file but i dont know what to write in my .aspx file..please helpme.
Thanks in advance.

解决方案

HI,

Here is a link which explains the dynamic grid creation with the headers please check this.

Dynamic gridview with headers

Thanks


In .cs file where you use sql query for gridview datasource like

select id, name,email from tablename 



By default query column name is your gridview header if you want to change it then you can use query as

select id as ID , name as [Customer Name] , email as Email from tablename




Please dont forget to Mark it as ans if you get help from it
Thanks
Hemant Singh


Your question is confusing. You say you have written some code in .cs file but do not know what to write in .aspx file? The title suggest you want to create gridview''s header dynamically. For that bit try the following code:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView grd = (GridView)sender;

GridViewRow HeaderRow = new GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Insert);

TableCell HeaderCell = new TableCell();
HeaderCell.Text = "First Column";
HeaderCell.Style["font-weight"] = "bold";
HeaderRow.Cells.Add(HeaderCell);

HeaderCell = new TableCell();
HeaderCell.Text = "Second Column";
HeaderCell.Style["font-weight"] = "bold";
HeaderRow.Cells.Add(HeaderCell);

HeaderCell = new TableCell();
HeaderCell.Text = "Third Column";
HeaderCell.Style["font-weight"] = "bold";
HeaderRow.Cells.Add(HeaderCell);

grd.Controls[0].Controls.AddAt(0, HeaderRow);
}
}



For any other requirement than this, please edit your question and post again.


这篇关于如何动态创建gridview的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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