如何在gridview ASP.NET VB中获取选定的超链接行 [英] How do I get selected hyperlink row in gridview ASP.NET VB

查看:37
本文介绍了如何在gridview ASP.NET VB中获取选定的超链接行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,适用于链接按钮如何调整代码,以便它适用于超链接:



我尝试过的:



< pre> Dim Lnkbtn  As  LinkBut​​ton =  CType (发件人,LinkBut​​ton)
Dim CommandName 作为 字符串 = Lnkbtn.CommandName
Dim CommandArgument As String = Lnkbtn.CommandArgument

strSQLCon = 数据源= xxxxxxxxxxxxx;初始目录= dbtesting; Trusted_Connection = True;
conConn = SqlConnection(strSQLCon)

Dim testrow As GridViewRow = GridView1.Rows(Lnkbtn.CommandArgument)
Dim strTblNbrLst As 字符串 = 没什么

对于 i < span class =code-keyword> As 整数 = 0 To 7

strTblNbrLst& = & testrow.Cells( 10 + i).Text

Next

strTblNbrLst = strTblNbrLst.TrimStart(

comComm = SqlCommand
使用 comComm

.Connection = conConn
.CommandType = CommandType.Text
.CommandText = SELECT * FROM tbl WHERE TblNbr IN ('& strTblNbrLst.Replace( ',')& ')ORDER BY TblNbr,LneNbr


结束 使用

' - 填写数据库le with the above
adpAdap = New SqlDataAdapter(comComm)
adpAdap.Fill(Datatbl)

Dim dv 作为 DataView(Datatbl) )
Dim arrTblNbrLst() As String = Strings.Split(strTblNbrLst,

' - 遍历每个表格编号并过滤表格
For i As Integer = 0 arrTblNbrLst.Count - 1

dv .RowFilter = TblNbr ='& arrTblNbrLst(i)& '

' - 遍历视图的每个行并在应用到文本框之前构建临时字符串
Dim strTemp 作为 字符串 = 没有

对于 k 作为 整数 = 0 dv.Count - 1
strTemp& = dv(k)( TxtDat).ToString
下一步

' - 选择正确的文本框
选择 案例 i
案例 0
TextBox2.Text = strTemp
案例 1
TextBox3.Text = strTemp
< span class =code-keyword> Case 2
TextBox4.Text = strTemp
案例 3
TextBox5.Text = strTemp
案例 4
TextBox6.Text = strTemp
案例 5
TextBox7.Text = strTemp
案例 6
TextBox8.Text = strTemp
案例 7
TextBox9。 Text = strTemp
Case Else

结束 选择
下一步


Catch ex As 异常

MsgBox( 错误:无法完成链接按钮事件。 & ex.Message& ex.StackTrace)

最后

如果 IsNothing(conConn)然后 conConn.Close( )

结束 尝试

结束 Sub

解决方案

我没有看到任何引用选定项目的代码。这应该是在事件处理程序中吗?为什么要隐藏这个事实?



为什么您希望/希望超链接的工作方式与链接按钮相同吗?



如果您希望它的行为类似于链接按钮,请使用链接按钮

I have the following code which works for a link button how to I adjust the code so it works for a hyperlink:

What I have tried:

<pre>Dim Lnkbtn As LinkButton = CType(sender, LinkButton)
Dim CommandName As String = Lnkbtn.CommandName
Dim CommandArgument As String = Lnkbtn.CommandArgument

strSQLCon = "Data Source=xxxxxxxxxxxxx;Initial Catalog=dbtesting;Trusted_Connection=True;"
conConn = New SqlConnection(strSQLCon)

Dim testrow As GridViewRow = GridView1.Rows(Lnkbtn.CommandArgument)
Dim strTblNbrLst As String = Nothing

For i As Integer = 0 To 7

strTblNbrLst &= "," & testrow.Cells(10 + i).Text

Next

strTblNbrLst = strTblNbrLst.TrimStart(",")

comComm = New SqlCommand
With comComm

.Connection = conConn
.CommandType = CommandType.Text
.CommandText = "SELECT * FROM tbl WHERE TblNbr IN ('" & strTblNbrLst.Replace(",", "','") & "') ORDER BY TblNbr, LneNbr"


End With

'-- Fill a datable with the above
adpAdap = New SqlDataAdapter(comComm)
adpAdap.Fill(Datatbl)

Dim dv As New DataView(Datatbl)
Dim arrTblNbrLst() As String = Strings.Split(strTblNbrLst, ",")

'-- Loop through each table number and filter on the table
For i As Integer = 0 To arrTblNbrLst.Count - 1

dv.RowFilter = "TblNbr = '" & arrTblNbrLst(i) & "'"

' -- Loop through each "row" of the view And build a temp string before applying to the textbox
Dim strTemp As String = Nothing

For k As Integer = 0 To dv.Count - 1
strTemp &= dv(k)("TxtDat").ToString
Next

'-- Select the correct textbox
Select Case i
Case 0
TextBox2.Text = strTemp
Case 1
TextBox3.Text = strTemp
Case 2
TextBox4.Text = strTemp
Case 3
TextBox5.Text = strTemp
Case 4
TextBox6.Text = strTemp
Case 5
TextBox7.Text = strTemp
Case 6
TextBox8.Text = strTemp
Case 7
TextBox9.Text = strTemp
Case Else

End Select
Next


Catch ex As Exception

MsgBox("Error: Unable to complete Link Button Event. " & ex.Message & ex.StackTrace)

Finally

If Not IsNothing(conConn) Then conConn.Close()

        End Try

End Sub

解决方案

I don't see any code referencing a "selected item". Is this supposed to be in an event handler? Why did you hide that fact?

Why do you expect / want a hyperlink to work the same way as a link button?

If you want it to behave like a "link button", then USE a link button.


这篇关于如何在gridview ASP.NET VB中获取选定的超链接行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆