ASP.NET GridView的标题行文本启用空当AllowSorting [英] ASP.NET GridView header row text empty when AllowSorting enabled

查看:469
本文介绍了ASP.NET GridView的标题行文本启用空当AllowSorting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我解决有趣的问题。我有一个GridView在我的应用程序,并单击按钮(在OnClick事件)后,我想获得选定的行和标题行。

I am solving interesting problem. I have a gridview in my application and after button click (in OnClick event) I am trying to get selected row and header row.

所有工作得很好,当电网不排序(AllowSorting =假)。这是我访问标题行单元格的方式:

All worked fine when the grid was not sortable (AllowSorting="false"). This is the way how I access the header row cells:

GridViewControl.HeaderRow.Cells[idx].Text

但是,一旦我在整理交换(AllowSorting =真),这种做法是行不通的。创建标题行,前pression GridViewControl.HeaderRow.Cells.Count返回列的正确数量,但GridViewControl.HeaderRow.Cells [IDX]。文本属性始终是空的!尽管如此,页面上就会显示网格视图中正确包括标题栏文本...

But, once I switched on sorting (AllowSorting="True"), this approach does not work. Header row is created, expression GridViewControl.HeaderRow.Cells.Count returns the correct number of columns, but GridViewControl.HeaderRow.Cells[idx].Text property is always EMPTY! Nevertheless, on the page the grid view is displayed correctly including header column texts ...

我试图在网上找到,但没有成功的答案......我已经发现了一些类似的问题,但从来没有回答......所以,没有任何人知道启用排序时如何获得头排列文本?

I have tried to find the answer on the web but without success ... I have found some similar questions but never answered ... so, does anybody know how to get header row column texts when sorting is enabled?

感谢您提前。

PS:使用不建议我

GridVewControl.Columns[idx].Text

属性...有只是2编辑和放列;选择命令......剩下的列会自动生成。

property ... there are just 2 columns with Edit & Select commands ... rest columns are automatically generated.

推荐答案

这是因为当GridView的排序是使用一个LinkBut​​ton。

It's because when the gridview is sortable a LinkButton is used.

您需要的是这样的:

LinkButton Link = GridView1.HeaderRow.Cells[0].Controls[0] as LinkButton;

String Title = Link.Text;

这篇关于ASP.NET GridView的标题行文本启用空当AllowSorting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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