 |
| 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
|
|
|
|

July 6th, 2006, 05:13 PM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

July 7th, 2006, 10:52 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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)
|
|

July 8th, 2006, 02:45 PM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you for your quick reply. it works
|
|

July 8th, 2006, 02:49 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Glad to help :)
JIm
|
|

December 12th, 2006, 05:34 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
can i please see your working code for this?
|
|

December 12th, 2006, 11:23 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 12th, 2006, 11:27 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 12th, 2006, 11:54 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 12th, 2006, 11:57 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 12th, 2006, 12:03 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
|
|
 |