Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 October 25th, 2004, 04:14 PM
Registered User
 
Join Date: Aug 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid Item Question

Hi, everyone. I got a question for changing the contents of datagrid items before display the datagrid.
What I want to do is change the boolean value(True/False) in the database table to Yes/No string before the page display the table, and the table is in datagrid. I think e.Item.Cells(2).Text should return all the boolean values from the datagrid. However, it only returns empty string. Here is my code:

Sub dgLibrary_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgLibrary.ItemDataBound

   If e.Item.ItemType = ListItemType.Item
      Or e.Item.ItemType=ListItemType.AlternatingItem Then
        If e.Item.Cells(2).Text = "True" Then
           e.Item.Cells(2).Text = "Yes"
        End if
   End If
End If
End Sub

Thanks a lot!

Kai

 
Old October 26th, 2004, 06:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

The boolean value is in a bound column? If in a templatecolumn, you have to find the control using FindControl(). It may be easier to do:

If CType(e.Item.Cells(2).Text, Boolean) Then
  'Write out yes

Brian
 
Old October 26th, 2004, 09:39 AM
Registered User
 
Join Date: Aug 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Brian. your idea really helped, and it works now! here is my new code:

Sub dgLibrary_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgLibrary.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim lblBoolean As Label

            lblBoolean = CType(e.Item.FindControl("Label1"), Label)
            If lblBoolean.Text = "True" Then
                e.Item.Cells(2).Text = "Yes"
            Else
                e.Item.Cells(2).Text = "No"
            End If
        End If
End Sub

 
Old October 26th, 2004, 12:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Glad to hear it. Note that you can also do e.Item.Cells(0).Controls(0), by index.





Similar Threads
Thread Thread Starter Forum Replies Last Post
display datagrid item shwetarani2002 ASP.NET 1.0 and 1.1 Basics 1 July 16th, 2007 07:47 AM
Datagrid Item Template question dparsons ASP.NET 1.0 and 1.1 Professional 3 March 14th, 2007 09:08 AM
Selecting a particular item in Datagrid muskaanbajaj ASP.NET 1.0 and 1.1 Professional 13 December 1st, 2005 07:47 AM
? DataGrid Item [email protected] ASP.NET 1.0 and 1.1 Professional 0 November 18th, 2003 08:56 AM





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