7 Replies - 1576 Views - Last Post: 19 December 2013 - 09:27 AM Rate Topic: -----

#1 tothanhtuan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-December 13

Quick question / How to validate checked checkboxlist loaded from data

Posted 18 December 2013 - 03:45 AM

Hello There

I've got 5 checkboxlists as below ,and each checkboxlist consisted 15 checboxes

i want to know how can we know the checkboxlists are checked or not ,

my database is like this

Id : int

rowd :nvarchar(250)

rowe:nvarchar(250)

rowf:nvarchar(250)

rowg:nvarchar(250)

rowh:nvarchar(250)

i was trying to save the checkboxlists state into session , but it is not useful cos each time when i click a check box , it will save all the existing checked checkboxlists to my database . i'm coding asp.net vb.net
Posted Image
So can you help me out ? thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Quick question / How to validate checked checkboxlist loaded from data

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9494
  • View blog
  • Posts: 35,842
  • Joined: 12-June 08

Re: Quick question / How to validate checked checkboxlist loaded from data

Posted 18 December 2013 - 07:49 AM

Why oh why are you storing checbox states as varchar250)?! They are boolean or bits. True or false!

If it's a normal ASP control you should be able to cycle through the checkboxes with the 'items' property... it's the collection of the textboxes.

CheckBoxList1.Items()


            <asp:CheckBoxList ID="CheckBoxList1" runat="server">
                <asp:ListItem id="bOption1" Text="bOption1" ></asp:ListItem>
                <asp:ListItem id="bOption2" Text="bOption2"></asp:ListItem>
            </asp:CheckBoxList>



CheckBoxList1.Items(1).Value

Was This Post Helpful? 0
  • +
  • -

#3 tothanhtuan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-December 13

Re: Quick question / How to validate checked checkboxlist loaded from data

Posted 18 December 2013 - 06:19 PM

View Postmodi123_1, on 18 December 2013 - 07:49 AM, said:

Why oh why are you storing checbox states as varchar250)?! They are boolean or bits. True or false!

If it's a normal ASP control you should be able to cycle through the checkboxes with the 'items' property... it's the collection of the textboxes.

CheckBoxList1.Items()


            <asp:CheckBoxList ID="CheckBoxList1" runat="server">
                <asp:ListItem id="bOption1" Text="bOption1" ></asp:ListItem>
                <asp:ListItem id="bOption2" Text="bOption2"></asp:ListItem>
            </asp:CheckBoxList>



CheckBoxList1.Items(1).Value

oh because in my case i want to check the Row D1,D2,D3,D4 and then it will be saved in my database ,
as you know D1,D2,D3,D4 so i can't set it as bit or boolean .
If you load it in pageload , it will show the state of the seat , checked or unchecked .
can you suggest me some advice ?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9494
  • View blog
  • Posts: 35,842
  • Joined: 12-June 08

Re: Quick question / How to validate checked checkboxlist loaded from data

Posted 18 December 2013 - 06:36 PM

Quote

oh because in my case i want to check the Row D1,D2,D3,D4

I have no idea what this means.

Quote

then it will be saved in my database ,
as you know D1,D2,D3,D4 so i can't set it as bit or boolean .

Huh? You are storing the checkbox name? Why would you ever want to do that? You have a finite set of checkboxes, right? Storing those as their bit (and not column name) is faster to index, search, retrieve, and uses less space.
Was This Post Helpful? 0
  • +
  • -

#5 tothanhtuan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-December 13

Re: Quick question / How to validate checked checkboxlist loaded from data

Posted 19 December 2013 - 08:31 AM

View Postmodi123_1, on 18 December 2013 - 06:36 PM, said:

Quote

oh because in my case i want to check the Row D1,D2,D3,D4

I have no idea what this means.

Quote

then it will be saved in my database ,
as you know D1,D2,D3,D4 so i can't set it as bit or boolean .

Huh? You are storing the checkbox name? Why would you ever want to do that? You have a finite set of checkboxes, right? Storing those as their bit (and not column name) is faster to index, search, retrieve, and uses less space.

can you give me some examples ?thanks
my checkboxlist is in this picture

http://i69.photobuck...zps70ab44c6.jpg
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9494
  • View blog
  • Posts: 35,842
  • Joined: 12-June 08

Re: Quick question / How to validate checked checkboxlist loaded from data

Posted 19 December 2013 - 08:37 AM

I gave you an example.. with code.
Was This Post Helpful? 0
  • +
  • -

#7 tothanhtuan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-December 13

Re: Quick question / How to validate checked checkboxlist loaded from data

Posted 19 December 2013 - 09:24 AM

thanks , im saving to my database as true/false
here is my code
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim insertSql As String = "INSERT INTO tbinterest(interest) VALUES(@interest)"
        Using myConnection As New SqlConnection(connectionString)
            myConnection.Open()
            Dim myCommand As New SqlCommand(insertSql, myConnection)



            myCommand.Parameters.AddWithValue("@interest", SqlDbType.Bit).Value = 1


            myCommand.ExecuteNonQuery()
            myConnection.Close()
        End Using



my i get one problem , how can i load the checked state in page load ?
this is my code in page load

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Using myConnection As New SqlConnection(connectionString)

            Dim objCmd_team As SqlCommand = New SqlCommand("SELECT [interest] FROM [tbinterest]", myConnection)
            myConnection.Open()
            Dim objReader As SqlDataReader = objCmd_team.ExecuteReader()
            While (objReader.Read())
                Dim currentCheckBox As ListItem = chkApprovers.Items.FindByValue(objReader("interest"))
             
                    If currentCheckBox IsNot Nothing Then
                        currentCheckBox.Selected = True
                    End If
            End While

        End Using

This post has been edited by modi123_1: 19 December 2013 - 09:27 AM
Reason for edit:: use code tags

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9494
  • View blog
  • Posts: 35,842
  • Joined: 12-June 08

Re: Quick question / How to validate checked checkboxlist loaded from data

Posted 19 December 2013 - 09:27 AM

You know each column you are making true or false.. so just assign the values.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1