Results 1 to 10 of 10

Thread: datalist and txtboxes

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    datalist and txtboxes

    Hi there

    is there a way in vb.net to get the contents of a textbox in a Datalist? (not just the ID number, but other fields too!)

    thanks!

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    anyone?

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Is this the same question as in your other thread?

    VB Code:
    1. Dim int1 As Integer, int2 As Integer
    2.  
    3.         For int1 = 0 To DataList1.Items.Count - 1
    4.             For int2 = 1 To (DataList1.Items(int1).Controls.Count - 4) Step 2
    5.  
    6.                 Response.Write(CType(DataList1.Items(int1).Controls(int2), TextBox).Text.ToString)
    7.             Next
    8.         Next

    I am seriously not sure about the Step 2 part though, you can modify it.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    nope that dont work. says "specified cast is not valid"


  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    This example assumes that you have only textboxes in your datalist. What do you have?

    I also suggest you take a look here:
    http://www.aspnet101.com/aspnet101/aspnetcode.aspx

    and take a look at how they work with the datalist. If you do find anything, do post back and let me know, because I'm also working my way around these darned things.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    yeh i have textboxes in the datalist

    ok so im trying some code but gives me that table 0 could not be found!

    Code:
            Dim dr As DataRow
            Dim s As String
            For Each dr In Ds1.Tables(0).DefaultView
                s = s + " " & dr("id") & " " & dr("description")
            Next
    
            Response.Write(s)

    the other thing is, since the data retrieved from SQL is from multiple tables, what should the index or table name be??

    i have also named the session "ds1" but when i put that in the tables() it says

    "Object reference not set to an instance of an object"

    ??
    Last edited by Techno; Aug 9th, 2004 at 04:13 AM.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Show the code you're using to create the dataset, maybe that'll give us an idea.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    its a method that gets the results from sql:

    Code:
    ..
     ConnectionString = MACHINE_NAME
            query = query + SortOrderBy
            Dim mySQLCommand As New SqlClient.SqlCommand
            Dim sqladapter As New SqlClient.SqlDataAdapter
            Dim sqlconn As New SqlClient.SqlConnection(ConnectionString)
            Dim nof As Integer
    
    
            mySQLCommand.CommandText = query
            mySQLCommand.Connection = sqlconn
            sqladapter.SelectCommand = mySQLCommand
            sqladapter.Fill(Ds1)
            Session.Add("ds1", Ds1)
            DataList1.DataSource = Ds1
            DataList1.DataBind()
    
            nof = DataList1.Items.Count
            LblNOF.Text = "Results: " + nof.ToString()
    ..
    ..

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Hmm, I'm really not sure

    Can you try this:

    VB Code:
    1. sqladapter.Fill(Ds1, "RIBBIT")

    And then later,

    VB Code:
    1. For Each dr In Ds1.Tables("RIBBIT").DefaultView

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    sry took time to reply back, i got it sorted

    it was the ctype statement i had to use, and make a variable of type textbox, then in that variable issue the ctype command and make sure you put in the ctype command the NAME of the TEXTBOX and the TYPE it is (Textbox/label)


    but it now chucks me this error:

    Code:
    Object must implement IConvertible
    ??

    code:

    Code:
    ConnectionString = "workstation id=" & Chr(34) & "SDC-DEV66" & Chr(34) & ";packet size=4096;integrated security=SSPI;initial catalog=labtracker;persist security info=False"
    
            Dim sqladapter As New SqlClient.SqlDataAdapter
            Dim sqlconn As New SqlClient.SqlConnection(ConnectionString)
            Dim mySQLCommand As New SqlClient.SqlCommand("updateTableMT", sqlconn)
            sqlconn.Open()
            
            Dim mySQLParam As New SqlClient.SqlParameter("@id", SqlDbType.Int)
            'commandtext
            mySQLCommand.CommandText = "updateTableMT"
            mySQLCommand.CommandType = CommandType.StoredProcedure
            Dim parameter As New SqlClient.SqlParameter("@id", SqlDbType.Int)
            parameter.Value = theID
            parameter.Direction = ParameterDirection.Input
            'parameter.DbType = DbType.Int32
            mySQLCommand.Parameters.Add(parameter)
            Dim adapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(mySQLCommand)
            adapter.Fill(Ds1) 'HERE IS THE ERROR!!!!!
            DataList1.DataSource = Ds1
            DataList1.DataBind()
            sqlconn.Close()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width