Can anybody provide me exact answer of this how to insert checkbox checked value to textbox in ascending order?
Can anybody provide me exact answer of this how to insert checkbox checked value to textbox in ascending order ?
Means if i check checkbox1 and checkbox3 then output in textbox ia 1,2
and if i check checkbox3 then checkbox1 then also output in textbox would be 1,2
I have asked this question ... previously but haven't found any exact work开发者_开发百科ing answer ...
Remember ,,, i have to use with 500+ checkboxes .... in asp.net(VB)
A little more information might be useful. Is this purely for the UI? In which case JavaScript via jQuery is probably what you need. Do the checkboxes AutoPostBack? In which case a server-side solution might be the answer, although client-side might still be appropriate even in this case.
Just put all your checkboxes in a ObjectModel.Collection(Of CheckBox) (here named myCol) Then during the loading make sure that you assign the hanler
For each chk as CheckBox in myCol
AddHandler chk.CheckedChanged, AddressOf PerformCheckUpdate
End For
Then you can perform the checked changed action in the Sub
Private Sub PerformCheckUpdate(Byval sender as object, byval e as eventargs)
Dim colResults as New ObjectModel.Collection(Of Integer)
For each chk as CheckBox in myCol
If chk.Checked Then
colResults.Add(chk.Name.Substring(8))
End If
Next
Dim intArray(colResults.Count - 1) as Integer
For i as Integer = 1 To colResults.Count
intArray(i-1) = colResults.Item(i-1)
Next
Array.Sort(intArray)
TextBox1.Text = ""
For i as Integer = 1 To colResults.Count
TextBox1.Text &= intArray(i-1)
If i< colResults.Count then
TextBox1.Text = ","
End If
Next
End Sub
It is not the most elegant solution, but it should work.
精彩评论