0

I'm currently trying to get some values from checkboxes that are "posted" to another aspx page. My code looks something like this:

<form method = "post" action = "HubPageUpdate.aspx">
    <input type = 'checkbox' name = 'customerBox' value = '0'>
    <input type = 'checkbox' name = 'customerBox' value = '1'>
    <input type = 'checkbox' name = 'customerBox' value = '2'>
    <input type = 'checkbox' name = 'customerBox' value = '3'>
    <input type = 'checkbox' name = 'customerBox' value = '4'>

    <input type = "submit" value = "Update">
</form>

My code generates the checkboxes dynamically, so it's not really hard coded. The ASP.NET page it is posting to is then to take what's checked, and I'll does some SQL to it. However, when I was testing it out by just using a simple:

<% Response.Write(Request.Form("customerBox")) %>

It would return to me what's checked as:

1,2,3

Which means the checkbox works, and that delights me. However, because it's a string, I can't really do much with it because I need them individually for SQL queries. How can I get them individually, and not as a string? I first assumed an array, but I still am not sure how to get them individually. Thanks!

1
  • ultimately, your question has nothing to do with where your data is coming from. Commented Apr 1, 2015 at 20:27

2 Answers 2

1

You assuming using an array was right (or atleast it's one way to do it). ;)

Not the shortest, but you can try this:

Dim RecievedString As String = "1,2,3"
Dim BoxesChecked() As Integer = New Integer() {}

For Each s As String In RecievedString.Split(",")
    Array.Resize(BoxesChecked, BoxesChecked.Length + 1)
    BoxesChecked(BoxesChecked.Length - 1) = Integer.Parse(s)
Next

Just assign RecievedString with what you get from the response.

BoxesChecked(0) will give you the first Integer in the array, BoxesChecked(1) the second one and so on...

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

Comments

0

So you just need a comma-separated string to be integers? Here's how you do that.

String stringValue = "1,2,3";
Dim asInts = From str in stringValue.Split(',')
    Select int.Parse(str);

My VB is rusty, so this might not be totally accurate.

4 Comments

Thanks! But this looks like C#, and I am not overly familiar with how to use C#. Is there a similar function in VB?
oh sorry, i forgot this was a VB question haha. i'll update my answer in a minute...
I've updated my question, hopefully that works / helps
Dim asInts = From str in stringValue.Split(',') Select int.Parse(str); Still quite new to VB, so I'm not too strong in it. What's happening from to the right of the Dim asInts?

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.