Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #21 (permalink)  
Old December 13th, 2006, 11:22 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have now managed to do this...(at last)


Protected Sub save_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim MyConnection As OdbcConnection

        MyConnection = New OdbcConnection() 'declare new connection object

        MyConnection.ConnectionString = " " 'database connect string

        MyConnection.Open() 'open connection to database

        Dim MyCommand As New OdbcCommand() 'declare new command object

        MyCommand.Connection = MyConnection

        Dim cID As Integer = 0
        ' Dim str As StringBuilder = New StringBuilder
        Dim i As Integer = 0
        Dim state As Integer
        For i = 0 To GridView1.Rows.Count - 1
            'Dim row As GridViewRow = GridView1.Rows(i)
            Dim isChecked As Boolean = CType(GridView1.Rows(i).FindControl("save"), CheckBox).Checked
            If isChecked Then
                state = 1
            Else
                state = 0
            End If

            MyCommand.CommandText = "update support.support set save =? where id=?"
            MyCommand.Parameters.Clear()
            MyCommand.Parameters.Add(New OdbcParameter("@state", state))
            MyCommand.Parameters.Add(New OdbcParameter("@id", GridView1.Rows(i).Cells(0).Text))
            MyCommand.ExecuteNonQuery()
        Next

        MyConnection.Close()
        MyCommand = Nothing
    End Sub


 All i need to do now is if a user checks a particular checkbox, it remains checked the next time they visit the page..

www.nursery-net.com
Reply With Quote
  #22 (permalink)  
Old January 30th, 2007, 10:31 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Speaking of checkboxes & gridviews...

Is it possible to have, say 7 rows, each with checkboxes. However, 3 rows the checkboxes are enabled, and 4 checkboxes are disabled. From my experience, it seems like all checkboxes are enabled, or all are disabled. Thanks for any ideas.
Reply With Quote
  #23 (permalink)  
Old January 30th, 2007, 10:39 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

yes you can.. you can control the value of every check box...

if you have the DG bounded and the checkbox field to a field in the database (boolean) then every checkbox will have the value that came from the db.

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
Reply With Quote
  #24 (permalink)  
Old January 31st, 2007, 05:17 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

similar thing to what i did before except i want to return the id of the row when the checkbox is clicked. can this be done?

www.nursery-net.com
Reply With Quote
  #25 (permalink)  
Old March 18th, 2010, 07:57 PM
Registered User
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default UpdatePanel

Quote:
Originally Posted by mike7510uk View Post
I have now managed to do this...(at last)


Protected Sub save_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim MyConnection As OdbcConnection

        MyConnection = New OdbcConnection() 'declare new connection object

        MyConnection.ConnectionString = " " 'database connect string

        MyConnection.Open() 'open connection to database

        Dim MyCommand As New OdbcCommand() 'declare new command object

        MyCommand.Connection = MyConnection

        Dim cID As Integer = 0
        ' Dim str As StringBuilder = New StringBuilder
        Dim i As Integer = 0
        Dim state As Integer
        For i = 0 To GridView1.Rows.Count - 1
            'Dim row As GridViewRow = GridView1.Rows(i)
            Dim isChecked As Boolean = CType(GridView1.Rows(i).FindControl("save"), CheckBox).Checked
            If isChecked Then
                state = 1
            Else
                state = 0
            End If

            MyCommand.CommandText = "update support.support set save =? where id=?"
            MyCommand.Parameters.Clear()
            MyCommand.Parameters.Add(New OdbcParameter("@state", state))
            MyCommand.Parameters.Add(New OdbcParameter("@id", GridView1.Rows(i).Cells(0).Text))
            MyCommand.ExecuteNonQuery()
        Next

        MyConnection.Close()
        MyCommand = Nothing
    End Sub


 All i need to do now is if a user checks a particular checkbox, it remains checked the next time they visit the page..

www.nursery-net.com
I'd suggest you to enable AutoPostBack on your CheckBox (inside the TemplateField) in order to make everything work as expected.

Then, put everything inside an AJAX UpdatePanel and make your end-user happy as if there was no PostBack occurring at all!

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

Your Stuff (GridView, SqlDataSource, etc...)

</ContentTemplate>
</asp:UpdatePanel>

Oh, of course there must be an ScriptManager on your page (one in the MasterPage would be fine).

Cheers,
Carlos
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView pady123 ASP.NET 2.0 Professional 0 November 13th, 2008 05:48 AM
Need your help about GridView khb3283 ASP.NET 2.0 Basics 1 November 9th, 2008 11:48 AM
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
How to Add CheckBoxField in ASP.NET creative.programmer ASP.NET 1.0 and 1.1 Basics 0 November 11th, 2007 05:47 PM
GridView simonwilbert ASP.NET 2.0 Basics 4 August 12th, 2006 02:40 AM



All times are GMT -4. The time now is 02:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.