473,480 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Select only one checkbox in looped checkboxes and get the corresponding textbox value

4 New Member
how can i select only one checkbox from looped checkboxes in a form and get the value of the textbox corresponds to it. Example is I have an ID and a username, i will add a username, the ID is automatically added because of increment. i have a checkbox and next to this is the textbox for Id and textbox for username, if i checked the checkbox then it will get the username and id. thank you for helping in advance :) this is my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form8_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'Dbase1DataSet.tbuser' table. You can move, or remove it, as needed. Me.TbuserTableAdapter.Fill(Me.Dbase1DataSet.tbuser) RefreshForm()
  2.  
  3.     strsql = "select * from tbuser order by ID desc"
  4.     sqlcmd.CommandText = strsql
  5.     sqlcmd.Connection = GetConnection()
  6.     adapter.SelectCommand = sqlcmd
  7.     adapter.Fill(dataset, "0")
  8.     Dim count = dataset.Tables(0).Rows.Count
  9.     If count > 0 Then
  10.         Dim r As DataRow
  11.         If dataset.Tables(0).Rows.Count <> 0 Then
  12.             For Each r In dataset.Tables(0).Rows
  13.                 For usernametxt = 0 To username_textbox.Length - 1
  14.  
  15.                 Next
  16.  
  17.                 For chckbx = 0 To chckbox.Length - 1
  18.  
  19.                 Next
  20.  
  21.                 For txt = 0 To txtboxnew.Length - 1
  22.  
  23.                 Next
  24.  
  25.                 ReDim Preserve username_textbox(usernametxt)
  26.                 ReDim Preserve chckbox(chckbx)
  27.                 ReDim Preserve txtboxnew(txt)
  28.  
  29.                 username_textbox(usernametxt) = New TextBox
  30.                 chckbox(chckbx) = New CheckBox
  31.                 txtboxnew(txt) = New TextBox
  32.  
  33.                 With username_textbox(usernametxt)
  34.                     .Name = "TextBox" & usernametxt.ToString()
  35.                     .Text = r("username")
  36.  
  37.                     If username_textbox.Length < 2 Then
  38.                         ' Position the first one.
  39.                         .SetBounds(186, 103, 100, 20)
  40.                     Else
  41.                         ' Position subsequent controls.
  42.                         .Left = username_textbox(usernametxt - 1).Left
  43.                         .Top = username_textbox(usernametxt - 1).Top + username_textbox(usernametxt - _
  44.                             1).Height + 4
  45.                         .Size = username_textbox(usernametxt - 1).Size
  46.                     End If
  47.  
  48.                     ' Save the control's index in the Tag property.
  49.                     ' (Or you can get this from the Name.)
  50.                     .Tag = usernametxt
  51.                 End With
  52.  
  53.  
  54.  
  55.  
  56.                 With chckbox(chckbx)
  57.                     .Name = "TextBox" & chckbx.ToString()
  58.                     .Text = r("ID")
  59.  
  60.                     If chckbox.Length < 2 Then
  61.                         ' Position the first one.
  62.                         .SetBounds(65, 105, 100, 20)
  63.                     Else
  64.                         ' Position subsequent controls.
  65.                         .Left = chckbox(chckbx - 1).Left
  66.                         .Top = chckbox(chckbx - 1).Top + chckbox(chckbx - _
  67.                             1).Height + 4
  68.                         .Size = chckbox(chckbx - 1).Size
  69.                     End If
  70.  
  71.                     ' Save the control's index in the Tag property.
  72.                     ' (Or you can get this from the Name.)
  73.                     .Tag = chckbx
  74.                 End With
  75.  
  76.  
  77.  
  78.  
  79.                 With txtboxnew(txt)
  80.                     .Name = "TextBox" & txt.ToString()
  81.  
  82.  
  83.                     If txtboxnew.Length < 2 Then
  84.                         ' Position the first one.
  85.                         .SetBounds(166, 102, 330, 103)
  86.                     Else
  87.                         ' Position subsequent controls.
  88.                         .Left = txtboxnew(txt - 1).Left
  89.                         .Top = txtboxnew(txt - 1).Top + txtboxnew(txt - _
  90.                             1).Height + 4
  91.                         .Size = txtboxnew(txt - 1).Size
  92.                     End If
  93.  
  94.                     ' Save the control's index in the Tag property.
  95.                     ' (Or you can get this from the Name.)
  96.                     .Tag = txt
  97.  
  98.                 End With
  99.                 Me.Controls.Add(txtboxnew(txt))
  100.                 Me.Controls.Add(username_textbox(usernametxt))
  101.                 Me.Controls.Add(chckbox(chckbx))
  102.             Next
  103.  
  104.         End If
  105.     End If
  106.  
  107. End Sub
  108.  
  109.  
  110. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  111.     For usernametxt = 0 To username_textbox.Length - 1
  112.         usernametextbox.Text = username_textbox(usernametxt).Text
  113.     Next
  114.  
  115.     strsql = "insert into tbuser (username) values ('" & usernametextbox.Text & "')"
  116.     sqlcmd.CommandText = strsql
  117.     sqlcmd.Connection = GetConnection()
  118.     sqlcmd.ExecuteNonQuery()
  119.     GetConnection.Close()
  120.     RefreshForm()
  121.  
  122. End Sub
button1 is the add button
Mar 5 '13 #1
5 2005
Rabbit
12,516 Recognized Expert Moderator MVP
Please use code tags when posting code.

I'm not actually sure what your question is. If you are saying there are multiple checkboxes on the form and you only want to allow the user to select one, then don't use checkboxes, use radio buttons.
Mar 5 '13 #2
Princess Zai
4 New Member
if that so, how can i get the textbox value next to that radio button?
Mar 6 '13 #3
Rabbit
12,516 Recognized Expert Moderator MVP
What textbox value next to a radio button? Radio buttons don't have textboxes.
Mar 6 '13 #4
Princess Zai
4 New Member
i have a radio button and two textboxes, all of them looped. in every radio btton there are 2 corresponding textboxes. example is in the textbox i input username and password, every i press the add button it will insert to the database and it will add another radio button and two textboxes if ever you want to add more. the problem is i will choose a username and password by means of radio button if the radio button is checked, i want to display in another form the username and password next to that radio button i clicked, how will i do that?
Mar 6 '13 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Well, it looks like you're uniquely assigning a name to each control. Use the unique name of the radio button to get to the textbox. IE, if I name the textbox, Text58 and the radio button, Radio58, if I click on Radio58, then I know to use Text58.
Mar 6 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4728
by: LRW | last post by:
I have no idea if this is more a PHP question or Javascript question, because my problem hinges equally on both. I have a PHP script that queries a database and creates a list of rows for each...
1
6011
by: Claire | last post by:
Hello, I am having a problem in my struts application with the checkboxes in my form. I have an array of checkboxes, some of which may be already selected when the form loads. My problem is when...
2
11036
by: Atreju | last post by:
Ok I got form within a c sharp page. Situation: On the form I have a drop downliwst and a textbox, the dropdownlist is populated with products and the textbox has a default vale of the product...
3
3141
by: technocraze | last post by:
Hi community experts, May I knw whether is it possible to display the corresponding value of the second textbox based on the user input in the first textbox? This means that once the user enters...
2
2467
by: Nowezo | last post by:
Hi, Can you please help me, I want to write a dropdown box that have an option 'Other' but when the Other is selected my textbox need to be enable and take the textbox value as an output instead of...
0
1280
by: Nathan Sokalski | last post by:
In the RadioButton and CheckBox controls, there is no Value attribute. The html <inputtag has a value attribute, which is used by both type="radio" and type="checkbox". The RadioButtonList and...
1
1777
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below...
2
3080
by: manishamca | last post by:
In dropdown i am retriving value from the backend. For eg: in the dropdown list the value selected are employee id..then i want to disply the emp name,job etc in the textbox. If i select a...
1
1903
by: benwizzle | last post by:
So basically I have a gridview that is selectable. Below it I have a dropdownlist and a textbox. The dropdownlist has the options for each column in the row(I am using an ajax autocomplete extender...
0
1549
by: yogarajan | last post by:
Hi All I am create textbox and collect textbox value at runtime using c# my aspx code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %> <!DOCTYPE html...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.