0

I am trying to use a label from another row in the gridview and insert it in a table when the user clicks the button which is in its own column.

my problem is that i cant get bookno which finds the label set to the @bookno in my sqldatasource

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
1
  • Are you getting any errors? And what does bookno.Text contains? Is it the parametername or the value? Commented May 18, 2011 at 19:35

1 Answer 1

1

Try

Dim bookno As Label = CType(selectedRow.Parent.FindControl("label1"), Label)

and see if you get a valid control for bookno. If it works, do the same for other FindControl() calls.

Sign up to request clarification or add additional context in comments.

1 Comment

what i did was just copied the sqldatasource into the booking template field set the label1 as the parameter control and just copied back the datasource to my outher templatefield and it worked great

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.