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 July 6th, 2006, 05:13 PM
Authorized User
 
Join Date: Jun 2006
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
 
Old July 7th, 2006, 10:52 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
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)


 
Old July 8th, 2006, 02:45 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your quick reply. it works

 
Old July 8th, 2006, 02:49 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Glad to help :)
JIm

 
Old December 12th, 2006, 05:34 AM
Authorized User
 
Join Date: Dec 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can i please see your working code for this?

 
Old December 12th, 2006, 11:23 AM
Authorized User
 
Join Date: Jun 2006
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
 
Old December 12th, 2006, 11:27 AM
Authorized User
 
Join Date: Dec 2006
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
 
Old December 12th, 2006, 11:54 AM
Authorized User
 
Join Date: Jun 2006
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
 
Old December 12th, 2006, 11:57 AM
Authorized User
 
Join Date: Dec 2006
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
 
Old December 12th, 2006, 12:03 PM
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.. 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





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.