簡體   English   中英

添加標題VB.net/asp.net gridview?

[英]Add headers VB.net/asp.net gridview?

我知道這個問題已經回答了,在C#中我一直試圖轉換並讓它工作,但是沒有成功嗎?

如果你幫忙,我將不勝感激

圖片

這是來自那個問題的圖像,我想做類似的事情。

這里是ASP.NET GridView第二個標題行的鏈接, 以跨越主標題行

Dim d As Date = Date.Today
        d = d.AddDays(-1)
        Label1.Text = d

        'connects to datawarehouse
        saocmd1.Connection = conn1
        conn1.Open()

        Dim ds As New DataSet

        'selects sql query
        'saocmd1.CommandText = MYQUERY"
        saoda1.Fill(saods1, "salesasoftable")

        Dim row As New GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal)

        Dim left As TableCell = New TableHeaderCell()
        left.ColumnSpan = 3
        row.Cells.Add(left)

        Dim totals As TableCell = New TableHeaderCell()
        totals.ColumnSpan = gridview1.Columns.Count - 3
        totals.Text = "Totals"
        row.Cells.Add(totals)

我的錯誤

Specified argument was out of the range of valid values.
Parameter name: index 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index

Source Error: 


Line 54:        row.Cells.Add(totals)
Line 55: 
Line 56:        Dim t As Table = TryCast(gridview1.Controls(0), Table)
Line 57:        If t IsNot Nothing Then
Line 58:            t.Rows.AddAt(0, row)

答案

Dim row As New GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal)

'spanned cell that will span the columns I don't want to give the additional header 
Dim left As TableCell = New TableHeaderCell()
left.ColumnSpan = 6
row.Cells.Add(left)

'spanned cell that will span the columns i want to give the additional header
Dim totals As TableCell = New TableHeaderCell()
totals.ColumnSpan = myGridView.Columns.Count - 3
totals.Text = "Additional Header"
row.Cells.Add(totals)

'Add the new row to the gridview as the master header row
'A table is the only Control (index[0]) in a GridView
DirectCast(myGridView.Controls(0), Table).Rows.AddAt(0, row)

從您的問題來看,您似乎無法將c#轉換為vb.net。 這里有2個可以提供幫助的在線轉換器。

http://www.developerfusion.com/tools/convert/csharp-to-vb/

http://converter.telerik.com/

或者有形軟件有一個可以轉換整個項目的轉換器,但請注意它不是免費的。

最簡單的方法是在RowCreated事件上處理此問題。 您將測試正在處理的RowType,如果它是標題,則您:

  1. 清除有問題的行單元格。
  2. 將第一個單元格的Rowspan調整為2(對於您的圖像:數量已發貨)。
  3. 緊接着刪除行單元格(對於您的圖像:總銷售額)。
  4. 創建一個新表,使其看起來像您想要的那樣,如圖所示。
  5. 將新表插入所需的行單元格。

如果你已經有了你想要使用的解決方案,但它是在C#而你無法轉換它,試試這個工具: http//www.developerfusion.com/tools/convert/csharp-to-vb/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM