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!
Printable View
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!
anyone?
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.
nope that dont work. says "specified cast is not valid"
:(
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.
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"
??
Show the code you're using to create the dataset, maybe that'll give us an idea.
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()
..
..
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
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()