简体   繁体   English

添加标题VB.net/asp.net gridview?

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

I know this question was answered, in C# and I have been trying to convert and get it to work, but have not been succesful? 我知道这个问题已经回答了,在C#中我一直试图转换并让它工作,但是没有成功吗?

I would greatly appreciate if you helped 如果你帮忙,我将不胜感激

图片

this is an image from that question, i want to do something similar. 这是来自那个问题的图像,我想做类似的事情。

here is the link ASP.NET GridView second header row to span main header row 这里是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)

my error 我的错误

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)

The 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)

From your question, it just seems that you are having trouble converting c# to vb.net. 从您的问题来看,您似乎无法将c#转换为vb.net。 Here are 2 online converters that can help out. 这里有2个可以提供帮助的在线转换器。

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

http://converter.telerik.com/ http://converter.telerik.com/

Or tangible software has a converter that can convert entire projects, but note that it is not free. 或者有形软件有一个可以转换整个项目的转换器,但请注意它不是免费的。

The simplest method is to handle this on the RowCreated event. 最简单的方法是在RowCreated事件上处理此问题。 You would test the RowType being handled, and if it is the header, you then: 您将测试正在处理的RowType,如果它是标题,则您:

  1. Clear the row cell(s) in question. 清除有问题的行单元格。
  2. Adjust the Rowspan of the first cell to 2 (in the case of your image: Qty Shipped). 将第一个单元格的Rowspan调整为2(对于您的图像:数量已发货)。
  3. Remove the row cell immediately following (in the case of your image: Total Sales). 紧接着删除行单元格(对于您的图像:总销售额)。
  4. Create a new table to look like the one you want as shown. 创建一个新表,使其看起来像您想要的那样,如图所示。
  5. Insert your new table into the row cell desired. 将新表插入所需的行单元格。

If you already have the solution you wish to use, but it's in C# and you can't convert it, try this tool: http://www.developerfusion.com/tools/convert/csharp-to-vb/ 如果你已经有了你想要使用的解决方案,但它是在C#而你无法转换它,试试这个工具: http//www.developerfusion.com/tools/convert/csharp-to-vb/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM