|
-
Aug 6th, 2004, 08:24 AM
#1
Thread Starter
PowerPoster
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!
-
Aug 7th, 2004, 04:48 AM
#2
Thread Starter
PowerPoster
-
Aug 9th, 2004, 01:16 AM
#3
Is this the same question as in your other thread?
VB Code:
Dim int1 As Integer, int2 As Integer
For int1 = 0 To DataList1.Items.Count - 1
For int2 = 1 To (DataList1.Items(int1).Controls.Count - 4) Step 2
Response.Write(CType(DataList1.Items(int1).Controls(int2), TextBox).Text.ToString)
Next
Next
I am seriously not sure about the Step 2 part though, you can modify it.
-
Aug 9th, 2004, 02:47 AM
#4
Thread Starter
PowerPoster
nope that dont work. says "specified cast is not valid"
-
Aug 9th, 2004, 04:02 AM
#5
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.
-
Aug 9th, 2004, 04:09 AM
#6
Thread Starter
PowerPoster
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.
-
Aug 9th, 2004, 04:56 AM
#7
Show the code you're using to create the dataset, maybe that'll give us an idea.
-
Aug 9th, 2004, 06:09 AM
#8
Thread Starter
PowerPoster
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()
..
..
-
Aug 9th, 2004, 06:56 AM
#9
Hmm, I'm really not sure 
Can you try this:
VB Code:
sqladapter.Fill(Ds1, "RIBBIT")
And then later,
VB Code:
For Each dr In Ds1.Tables("RIBBIT").DefaultView
-
Aug 11th, 2004, 03:17 AM
#10
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|