Getting checkbox values individually in ASP.NET through VB - html

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!

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...

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.

Related

Excel VBA Extracting Inner Text from href Tag

the HTML CODE look like this:
<div class="WebPageMessage">
<div class="WebPageMessageInformation">
<div class="Message">Your request has been scheduled. Job # 221816. Click here To monitor Schedule<br>There are 0 job(s) already in the queue.</div></div></div>
Desired result: Extract the text "Job # 221816..."
here is the code im trying to use but i am getting "object is no supported" error msg
Set foo = objIE.document.getElementsByClassName("Message").getElementsByTagName("a").innerText
Any help would be great
Thanks and happy holidays : )
It's because you are attempting to Set a string (innerText) to an Object. Also, you need to specify which Class Name "Message" you want and which tag name "a" you want.
You have two options:
Option 1: Set the object first, then grab string from foo
Dim foo As Object, myStr As String
Set foo = objIE.document.getElementsByClassName("Message")(0).getElementsByTagName("a")(0)
myStr = foo.InnerText
Option 2: Don't assign the object to a variable and just grab the string directly.
Dim myStr As String
myStr = objIE.document.getElementsByClassName("Message")(0).getElementsByTagName("a")(0).innerText
Notice how I placed (0) after the ClassName and TagName? That is subject to change dependent entirely on your full HTML code. Best method would be using a For Each...Next statement to iterate through all the ClassNames or TagNames, but you can specify which Class/Tag Names you want specifically by placing (i) after. Notice the 's' after getElements...? That's because class and a tag names are not unique. The only unique element is the ID (notice no 's' in getElementByID().

How to add labels dynamically to html

I'm getting data into my code behind file in the format of array list. The sproc will return several records depending upon the input parameter value. Now i need to display all these values in HTML as labels dynamically.
For example if i got 2 records, i just need to display those 2 records, if 10 records are returned then display 10 records. I don't want keep 10 static labels to bind all the time. I just looking to place only one label in html and want to use that one to display all the records returned by query. Will it be possible??
Sample code:
//Client side
<asp:Label ID="lblresult" runat="server" CssClass="label" ></asp:Label>
//server side
Dim arraylist as arrayList = //result from sproc
Dim lbltext As String = ""
For Each item In arraylist
Do While item.value = lbltext
Me.lblresult.Text = item.value
lbltext = item.value
Loop
Next
Please let me how to solve this? Thanks in advance!
Kinda late for this, but is this what you are looking for?
For i = 0 To YourArrayList.Count - 1
lblresult.Text &= YourArrayList(i).ToString & " "
Next
Also this will cause you an error:
Dim arraylist as arrayList = //result from sproc
arraylist is a reserved keyword. You might want to use another name.
You can try following technique which i often use in C#,Php etc:
hope this will give you an idea for doing it in your programming Language.
string rows;
for(int cnt=0;cnt<array.count;cnt++) {
rows = rows +""+array[cnt].value;
}
yourLable.text = rows; //here you are binding all your rows to your lable

How to store value in html without showing on page

I'm using Jinja2 and Google App Engine.
I identify my models with integer num:
class TestModel(db.Model):
value = db.StringProperty()
num = db.IntegerProperty()
and have a class for editing the value:
class Edit(Handler):
def get(self):
#show input box with value, let user edit value, render page with num
def post(self):
#get new value, filter database for model instance BY NUM and replace with new value
I need to store num on the page so I can retrieve it for the post method but I don't want the page to display it.
I tried:
<span name = "num" value = "{{num}}"></span>
and in the post method I have
num = self.request.get('num')
logging.error("NUM: %s" % num)
But when I run this, num doesn't show in the logs (I have "NUM: ") and I get
ValueError: invalid literal for int() with base 10: ''
When I render the page, the source code shows that num is there. Why isn't this code properly retrieving num?
Have you tried putting the field into a hidden input element. i.e.
<input type="hidden" name="..." value="..."/>
Also make sure that the value you are trying to retrieve in your post is within the form tags.

How do I set a variable to one of my form's listboxes in vba(access)?

I have a function that I want to return different Listboxes based on a string argument.
Here is the function:
Here is the function:
Private Function returnList(name As String) As AccessObject
If name = "app" Then
returnList = Me.Controls("List61")
'I have also tried the following:
'returnList = Me.List61, returnList = Forms![Daily Reports]![List61]
ElseIf name = "lpar" Then
'..several more cases
End If
End Function
Whenever I try to call it, I get a "Run-time error '91': Object variable or With block variable not set." And when I use the debugger, it tells me that the reference to list61(Me.list61, Me.Controls("List61")) is null.
Anyone have any idea how to fix this? Any help would me much appreciated.
The most important thing to note is; as you are now handling "Objects" instead of "variables" you have to put the word "Set" in front of the object variable. Also change the AccessObject type to ListBox.
Private Function returnList(name As String) As ListBox
If name = "app" Then
Set returnList = Me.Controls("List61")
'I have also tried the following:
'returnList = Me.List61, returnList = Forms![Daily Reports]![List61]
ElseIf name = "lpar" Then
'..several more cases
End If
End Function

Format number Rdlc report

i need to show numbers 1 2 3 in Arabic letters
i write in text box expression this statement
=FormatNumber(Fields!Size.Value,1,-2,-2,-2)
but i don't know it's parameter and which parameter can show numbers in Arabic format
MANY THANKS
set report language to your local language (ar-EG)
in the textbox properties set NumeralVariant to 3
references
similar problem
NumeralVariant
limitations
1- will not work for strings containing numbers
2- will not work for dates
work around limitation with bad performance i guess
you can replace any english number with arabic number using Replace method in any string that may contain numbers
your expression will be some thing like this
=Replace(Replace(Replace(Fields!FieldName.Value,"0","۰"),"1","۱"),"2","۲")
complete expression to 9
You can write function in code and use that
enter image description here
Public Shared Function farsi(input As String) As String
Dim result As String = input
result = result.Replace("1", "۱")
result = result.Replace("2", "۲")
result = result.Replace("3", "۳")
result = result.Replace("4", "۴")
result = result.Replace("5", "۵")
result = result.Replace("6", "۶")
result = result.Replace("7", "۷")
result = result.Replace("8", "۸")
result = result.Replace("9", "۹")
result = result.Replace("0", "۰")
Return result
End Function
Usage:
=Code.farsi(1111.555)
Public Shared Function Arabic(input As String) As String
Dim result As String = input
result = result.Replace("1", "۱")
result = result.Replace("2", "۲")
result = result.Replace("3", "۳")
result = result.Replace("4", "٤")
result = result.Replace("5", "۵")
result = result.Replace("6", "٦")
result = result.Replace("7", "۷")
result = result.Replace("8", "۸")
result = result.Replace("9", "۹")
result = result.Replace("0", "۰")
Return result
End Function
Use it for arabic Numbers
=Code.Arabic(Fields!OrderID.Value)
=Code.Arabic(FieldName)