Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 June 12th, 2006, 01:41 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to check the value of a field

Hi,

The aspx file contains a datasource and a gridview.
The (only) field is a boolean type (true/false).
Now, when the value of the field is 'true' something must happen (the backgroundcolor must be red).
So i used the server-event 'GridView1_RowCreated' but how can i check the value of the field on each row in the code-behind?
I tried this code below, but it doesn't work ...
Thanks

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=c:\mydb.mdb"
ProviderName="System.Data.OleDb" SelectCommand="SELECT field1 from
mytable"></asp:SqlDataSource>
 <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
<Columns><asp:BoundField DataField="myfield" /> </Columns>
</asp:GridView>

The code-behind:
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
Dim a As DataControlField
a = GridView1.Columns(0)
...
End Sub
(variable 'a' contains the name of the field but there is nothing i can put after 'Columns(0).' , like "value" or something ...)



 
Old June 12th, 2006, 04:08 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You need to use the RowDataBound event, otherwise the data is not bound and you can't check the state of the checkbox.
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim cb As New CheckBox
            cb = e.Row.Cells(0).Controls(0)
            If cb.Checked Then
                e.Row.Cells(0).BackColor = Drawing.Color.Red
            End If
        End If
Jim

 
Old June 13th, 2006, 02:49 PM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, it works ...

 
Old June 13th, 2006, 03:53 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

glad to help...






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check the password field for case-sensitive zubash73 ASP.NET 2.0 Basics 4 November 27th, 2016 02:47 AM
Connect to VSS check-in Check-out Programatically rhd110 General .NET 6 August 12th, 2007 07:46 AM
check for image field exist goldenstate ASP.NET 2.0 Basics 2 May 22nd, 2007 12:36 PM
Change check box field to false in MS Acess VB saban ASP.NET 1.0 and 1.1 Basics 0 March 13th, 2007 05:19 AM
Need HELP!!! Record Input in Field - Check box on karlzoe BOOK: Beginning ASP 3.0 1 April 7th, 2005 09:51 AM





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