none
FormView RRS feed

  • Question

  •  

    Hi Guys I have a formiew that I have edited By adding a few textboxes to it and bind these textboxes to data coming from a table using an sqldatasource. Now I would like to write my own update statement to update the data. I am having a had time accessing the value in the textboxes once they a populated. I am trying something like this but it does not work

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUodate.Click

    Dim TextBox1 As TextBox

    Dim TextBox2 As TextBox

    Dim TextBox3 As TextBox

    Dim TextBox4 As TextBox

    Dim TextBox5 As TextBox

    Dim TextBox6 As TextBox

     

    TextBox1 = New TextBox

    TextBox2 = New TextBox

    TextBox3 = New TextBox

    TextBox4 = New TextBox

    TextBox5 = New TextBox

    TextBox6 = New TextBox

     

    If IsPostBack Then

    Dim TextBox1 As TextBox = CType(FormView1.FindControl("TextBox1"), TextBox)

    Dim TextBox2 As TextBox = CType(FormView1.FindControl("TextBox2"), TextBox)

    Dim TextBox3 As TextBox = CType(FormView1.FindControl("TextBox3"), TextBox)

    Dim TextBox4 As TextBox = CType(FormView1.FindControl("TextBox4"), TextBox)

    Dim TextBox5 As TextBox = CType(FormView1.FindControl("TextBox5"), TextBox)

    Dim TextBox6 As TextBox = CType(FormView1.FindControl("TextBox6"), TextBox)

     

    End If

    The Connection string and update command come here

     

    End Sub

    Can some kindly help

     

    Thanks Trafmore.

    Monday, October 22, 2007 7:36 PM

Answers

  •  Trafmore wrote:

     

    Hi Guys I have a formiew that I have edited By adding a few textboxes to it and bind these textboxes to data coming from a table using an sqldatasource. Now I would like to write my own update statement to update the data. I am having a had time accessing the value in the textboxes once they a populated. I am trying something like this but it does not work

    Can some kindly help

     

    Thanks Trafmore.

     

    Hi,

     

    Why don't you add the textboxes as design time instead of run time?

     

    If you must add them at run-time then do

     

    Me.Controls.Add(TextBox1) ' etcetera

     

    If you need to update the textboxes access the text property of each which is a STRING.

     

    TextBox1.Text = "Whatever ?!"

     

    To access the value in a textbox put it in a string first or test to see if it a number first ( if you need to ).

     

     

    Code Block

     

    Dim myDouble As Double = 0

    'See if the text is a number first.

    If IsNumeric(TextBox1.Text) Then

    myDouble = Val(TextBox1.Text)

    End If

     

     

    Sorry I can't help further as I have not done any database stuff with VB.Net yet.

     

     

     

     

    Regards,

     

    John

     

    Monday, October 22, 2007 8:47 PM
  • I did think of doing that way but the reason I did not is because I want the form designed is a specific way. I But I will try it anyway. Thanks much

    Trafmore

     

    Tuesday, October 23, 2007 12:42 PM

All replies

  •  Trafmore wrote:

     

    Hi Guys I have a formiew that I have edited By adding a few textboxes to it and bind these textboxes to data coming from a table using an sqldatasource. Now I would like to write my own update statement to update the data. I am having a had time accessing the value in the textboxes once they a populated. I am trying something like this but it does not work

    Can some kindly help

     

    Thanks Trafmore.

     

    Hi,

     

    Why don't you add the textboxes as design time instead of run time?

     

    If you must add them at run-time then do

     

    Me.Controls.Add(TextBox1) ' etcetera

     

    If you need to update the textboxes access the text property of each which is a STRING.

     

    TextBox1.Text = "Whatever ?!"

     

    To access the value in a textbox put it in a string first or test to see if it a number first ( if you need to ).

     

     

    Code Block

     

    Dim myDouble As Double = 0

    'See if the text is a number first.

    If IsNumeric(TextBox1.Text) Then

    myDouble = Val(TextBox1.Text)

    End If

     

     

    Sorry I can't help further as I have not done any database stuff with VB.Net yet.

     

     

     

     

    Regards,

     

    John

     

    Monday, October 22, 2007 8:47 PM
  • I did think of doing that way but the reason I did not is because I want the form designed is a specific way. I But I will try it anyway. Thanks much

    Trafmore

     

    Tuesday, October 23, 2007 12:42 PM