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
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 Display Modes
  #1 (permalink)  
Old July 6th, 2006, 05:13 PM
Authorized User
 
Join Date: Jun 2006
Location: Chelmsford, MA, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default CheckBoxField in GridView

Here is my gridview code:

    <asp:GridView HorizontalAlign=left Width="98%" ID="GVAIns" AllowSorting="False" runat="server" AutoGenerateColumns="False">
      <Columns>
        <asp:BoundField HeaderText="Institution_ID" DataField="Institution_ID" SortExpression="Institution_ID" Visible=false />
        <asp:BoundField HeaderStyle-HorizontalAlign=center HeaderText="Institution Name" DataField="Institution_Name" SortExpression="Institution_Name" />
        <asp:CheckBoxField ReadOnly="false" ItemStyle-HorizontalAlign=Center DataField="Day_Event_Exists" />
      </Columns>
    </asp:GridView>


i think by default checkboxes are disabled. I want to enable all checkbox items, so that user can check or uncheck. How can i do that and how can i retrieve these values?

Any help greatly appreciated.
Thanks


__________________
Rams
Reply With Quote
  #2 (permalink)  
Old July 7th, 2006, 10:52 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,346
Thanks: 0
Thanked 5 Times in 5 Posts
Default

set the checked property to true for the checkbox.

To get the values, you need to use the RowDataBound event and get a reference to the checkbox and get it's checked state(True or False)


Reply With Quote
  #3 (permalink)  
Old July 8th, 2006, 02:45 PM
Authorized User
 
Join Date: Jun 2006
Location: Chelmsford, MA, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your quick reply. it works

Reply With Quote
  #4 (permalink)  
Old July 8th, 2006, 02:49 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,346
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Glad to help :)
JIm

Reply With Quote
  #5 (permalink)  
Old December 12th, 2006, 04:34 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can i please see your working code for this?

Reply With Quote
  #6 (permalink)  
Old December 12th, 2006, 10:23 AM
Authorized User
 
Join Date: Jun 2006
Location: Chelmsford, MA, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry. We have modified our code and no longer we are using checkboxes and hence i don't have working code for this. Please tell here your problem, so that we can figure it out.

Thanks

Rams
Reply With Quote
  #7 (permalink)  
Old December 12th, 2006, 10:27 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have a gridview with several columns and a templatefield containing a checkbox. when the user clicks the checkbox i want to update the database with a 1 (if checked) or a 0 (if unchecked). also, it must only update the row that was checked and not the entire thing

www.nursery-net.com
Reply With Quote
  #8 (permalink)  
Old December 12th, 2006, 10:54 AM
Authorized User
 
Join Date: Jun 2006
Location: Chelmsford, MA, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can find that checkbox using gridview item. find method for each row and use .checked method whether its checked or not.. and update your database.

Thanks
Rama

Rams
Reply With Quote
  #9 (permalink)  
Old December 12th, 2006, 10:57 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i tried that already and cant get it to work...here is code i have so far...

Code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

        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



        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim Chk As CheckBox = e.Row.Cells(5).FindControl("save")



            If Chk.Checked = True Then
                MyCommand.CommandText = "update support.support set save = 1"



            End If

            If Chk.Checked = False Then
                MyCommand.CommandText = "update support.support set save = 0"



            End If


            MyCommand.ExecuteNonQuery()

            MyConnection.Close()

            MyCommand = Nothing



            'MsgBox(Chk.Checked) 



        End If

    End Sub


www.nursery-net.com
Reply With Quote
  #10 (permalink)  
Old December 12th, 2006, 11:03 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,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. you only want to update the DB only when the user click any of the checkboxes?

b/c you are using the wrong event if that is the case..

HTH

Gonzalo
Reply With Quote
Reply


Thread Tools
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 04:48 AM
Need your help about GridView khb3283 ASP.NET 2.0 Basics 1 November 9th, 2008 10: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 04: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 07:46 PM.


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