gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:36:34 28 4
gpt4 key购买 nike

我知道这个问题已经在 C# 中得到了回答,我一直在尝试转换并让它工作,但没有成功?

如有帮助,将不胜感激

image

这是那个问题的图片,我想做类似的事情。

这是链接 ASP.NET GridView second header row to span main header row

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/

tangible software有一个转换器可以转换整个项目,但请注意它不是免费的。

关于asp.net - 添加标题 VB.net/asp.net gridview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4388836/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com