Asp.net 在sqldatasource insert命令中使用gridview行控件

Asp.net 在sqldatasource insert命令中使用gridview行控件,asp.net,vb.net,Asp.net,Vb.net,我试图使用gridview中另一行的标签,并在用户单击自己列中的按钮时将其插入表中 我的问题是我无法获取bookno,它在我的sqldatasource中找到了设置为@bookno的标签 Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim selectedRow As Button = DirectCast(sender, Button) D

我试图使用gridview中另一行的标签,并在用户单击自己列中的按钮时将其插入表中

我的问题是我无法获取bookno,它在我的sqldatasource中找到了设置为@bookno的标签

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim selectedRow As Button = DirectCast(sender, Button)



        Dim bookno As Label = CType(selectedRow.FindControl("label1"), Label)
        Dim why As TextBox = CType(selectedRow.FindControl("textbox2"), TextBox)
        Dim yesint As Integer = 1
        Dim sql As SqlDataSource = CType(selectedRow.FindControl("sqldatasource4"), SqlDataSource)
        sql.InsertParameters.Add(bookno.Text, 0)


        sql.Insert()

    End Sub
试一试


并查看是否获得
bookno
的有效控件。如果有效,请对其他
FindControl()
调用执行相同的操作。

是否有任何错误?bookno.Text包含什么?是parametername还是value?我所做的只是将sqldatasource复制到booking template字段中,将label1设置为参数控件,然后将datasource复制回outher templatefield,效果非常好
Dim bookno As Label = CType(selectedRow.Parent.FindControl("label1"), Label)