Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2006, 11:22 AM
Authorized User
 
Join Date: Dec 2006
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
 
Old January 30th, 2007, 10:31 AM
Registered User
 
Join Date: Jan 2007
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.
 
Old January 30th, 2007, 10:39 AM
Friend of Wrox
 
Join Date: Jun 2003
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
================================================== =========
 
Old January 31st, 2007, 05:17 AM
Authorized User
 
Join Date: Dec 2006
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
 
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.