2009-08-31 44 views
4

關於產品的GridView在VB.NET排序:的GridView的AutoGenerateColumns和排序

我有AutoGenerateColumns = True

<asp:GridView ID="GridView1" FooterStyle-BackColor="Aquamarine" 
    AutoGenerateColumns="true" AllowSorting="true" OnSorting="Gridview1_Sorting" 
    AllowPaging="True" PageSize="12" OnRowCreated="GridView1_RowCreated" 
    RowStyle-Wrap="true" runat="server" Width="100%" > 
    <HeaderStyle BackColor="#E0E0E0" ForeColor="#000000"/> 
    <FooterStyle BackColor="Aquamarine" /> 
     <emptydatarowstyle backcolor="#CBE0FD" forecolor="#0000FF"/> 
</asp:GridView> 

我已經聲明瞭排序事件處理(OnSorting="Gridview1_Sorting")一個GridView,並能正常工作。

不過,後來我更改列標題(標題,因爲他們是在我從數據庫中獲取的數據集)

GridView1.HeaderRow.Cells(0).Text = "Document" ' "PROC_UID" 
GridView1.HeaderRow.Cells(1).Text = "Process Step" ' "PROC_DOC_UID" 

當我設置HeaderRow文本,我不能再點擊標題排序(它也不再下劃線)。 我該如何糾正?

回答

4

http://forums.asp.net/p/996470/1691883.aspx#1691883

你需要找到控件集內的鏈接按鈕,然後更新鏈接文本。

+0

最優秀的。需要更換 「」 與 等的HTMLEncode鏈接按鈕文本 昏暗tblThisCell作爲TableCell的 對於每個tblThisCell在e.Row.Cells 嘗試 昏暗lnkBut​​ton作爲的LinkBut​​ton = tblThisCell.Controls(0) 選擇案例lnkBut​​ton.Text 案 「DOC_Bezeichnung」 lnkBut​​ton.Text = 「庫門」 最終選擇 抓住EX作爲例外 MyDebug.MsgBox(ex.Message) 結束Try 接下來 結束如果 –

2

您可以通過在由網格使用的SQL查詢您的別名列更改列標題:

Select ColumnA as [Whatever], ColumnB as [Name It This] From Table .... 
+0

最好的方式做到這一點! – TheVillageIdiot

+0

也不錯,但給我的問題,因爲用這種方法,我不得不改變我的查詢。 –