Add VB.net/asp.net gridview headers?

I know that this question was answered, in C #, and I tried to convert and make it work, but was not successful?

I would really appreciate if you could help

image

This is an image from this question, I want to do something like that.

here is the second ASP.NET GridView header line link to cover the main title bar

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)

my mistake

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)

Answer

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)
+3
source share
2 answers

From your question, it just seems like it's hard for you to convert C # to vb.net. Here are 2 online converters that can help.

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

http://converter.telerik.com/

, , , .

+3

- RowCreated. RowType, , :

  • .
  • 2 ( : Qty ).
  • ( : ).
  • , , .
  • .

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

0

Source: https://habr.com/ru/post/1779195/


All Articles