本文介绍了如何在gridview ASP.NET VB中获取选定的超链接行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有以下代码,适用于链接按钮如何调整代码,以便它适用于超链接: 我尝试过的: < pre> Dim Lnkbtn As LinkButton = CType (发件人,LinkButton) 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 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 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.CommandNameDim CommandArgument As String = Lnkbtn.CommandArgumentstrSQLCon = "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 = NothingFor i As Integer = 0 To 7strTblNbrLst &= "," & testrow.Cells(10 + i).TextNextstrTblNbrLst = strTblNbrLst.TrimStart(",")comComm = New SqlCommandWith 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 aboveadpAdap = 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 tableFor i As Integer = 0 To arrTblNbrLst.Count - 1dv.RowFilter = "TblNbr = '" & arrTblNbrLst(i) & "'"' -- Loop through each "row" of the view And build a temp string before applying to the textboxDim strTemp As String = NothingFor k As Integer = 0 To dv.Count - 1strTemp &= dv(k)("TxtDat").ToStringNext'-- Select the correct textboxSelect Case iCase 0TextBox2.Text = strTempCase 1TextBox3.Text = strTempCase 2TextBox4.Text = strTempCase 3TextBox5.Text = strTempCase 4TextBox6.Text = strTempCase 5TextBox7.Text = strTempCase 6TextBox8.Text = strTempCase 7TextBox9.Text = strTempCase ElseEnd SelectNextCatch ex As ExceptionMsgBox("Error: Unable to complete Link Button Event. " & ex.Message & ex.StackTrace)FinallyIf Not IsNothing(conConn) Then conConn.Close() End TryEnd 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中获取选定的超链接行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-18 18:30