Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Bonnie Berent's Tips
Bonnie DeWitt, February 1, 2008
Great tips from the Universal Thread .NET community.
Summary
Great tips from the Universal Thread .NET community.
Description

Debugging With Parameters
Usually when you run and debug your application, you just hit F5 to compile and start debugging. But, what do you do if you require input parameters?

Right-click on your Startup Project in the Solution Explorer and choose Properties. Then, on the Debug page you can enter command line arguments.

from a solution provided by Viv Phillips in Message #1241577

Does Column Exist
If all I have is a DataRow, how can I determine if a specific column exists in that DataRow?
If (dataRow.Table.Columns.Contains("FirstName"))
	' do something
End If

from a solution provided by John Baird in Message #1170955

Tweaking Displayed cells on a Web Page's GridView
In a Web Page GridView, how do you handle updating the value of some columns before displaying them. For example, a column of the GridView displays the status of the record.

If the status is 'P', change it to display 'Pass'.
If the status is 'F', change it to display 'Fail'.

There are at least two ways to handle this, maybe more.

First, you can put a subroutine into the code-behind of the page, coded to accept a string character and return a string value. Then, use an ItemTemplate to define the binding expression for that column as the return value of your sub call (passing in the Container.DataItem as the parameter). You can see an example of this in VB here (there is also a C# example linked on that page, too):

http://dotnetjunkies.com/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/data/DataBind6.src&file=DataBind6_vb.aspx

Or, you can trap the RowDataBound event of the DataGrid, check the RowType property to see if it's a data row, and refer to the cell and change its Text value according to the value you find already there. Here is an example from .NET help for RowDataBound event that sets the text to italic tags around the existing value. You could put IF logic there to check the existing value and set a different value accordingly.

Here is the VB italics sample from RowDataBound help, to point you in the right direction (NOTE: you have to either set the OnRowDataBound property of the GridView to point to this subroutine or you have to add a "Handles" clause at the end of the first line that declares the Sub):

Sub CustomersGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.DataRow Then
    
      ' Display the company name in italics.
      e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text & "</i>"
        
    End If
    
  End Sub
Or, third, why not just have the object that your ObjectDataSource is bound to instead do the transformation for you in the method call you use for SelectCommand, so your select command returns the data just like you need it? I know that puts data "formatting" into the business object layer, but it's also a solution if you have problems getting the display layer to behave as you want.

The RowDataBound looks like a good solution if you can count on the column staying in the SAME order -- because you refer to the Cell by position in the cells collection (zero-based). If the column order changes for some reason, the code will fail. Therefore, the subroutine in the page-behind and a binding expression looks like the safest approach to me.

from a solution provided by David Stevenson in Message #1141576

Display an Image in a DataGridView Header
Naomi comes up with a link to the MSDN forums, explaining how to accomplish this. I thought about copy/pasting the code here, but it's a lot. Better to just click on the link and get it straight from the horses mouth. =0)

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=233259&SiteID=1

from a solution provided by Naomi Nosonovsky in Message #1244475

Bonnie DeWitt, Geneva Systems Group
Bonnie is currently one of the principals of Geneva Systems Group. Call her the Senior Software Engineer, or even call her the VP of Engineering. She has no official title at the moment. Bonnie has been writing software in various languages for about 30 years. Bonnie's current focus on C# .NET applications began in early 2002. She has been a Microsoft C# MVP since Oct 2003 and an active member of the .NET online community.
More articles from this author
Bonnie DeWitt, September 1, 2005
Great tips for .NET developers
Bonnie DeWitt, October 1, 2005
Great tips for .NET developers
Bonnie DeWitt, November 1, 2005
Great tips for .NET developers
Bonnie DeWitt, December 1, 2005
Great tips for .NET developers
Bonnie DeWitt, April 1, 2009
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, February 1, 2006
Great tips for .NET developers
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers
Bonnie DeWitt, April 1, 2006
Great tips for .NET developers
Bonnie DeWitt, May 1, 2006
Great tips for .NET developers
Bonnie DeWitt, June 1, 2006
Great tips for .NET developers
Bonnie DeWitt, July 1, 2006
Great tips for .NET developers
Bonnie DeWitt, August 1, 2006
Great tips for .NET developers
Bonnie DeWitt, September 1, 2006
Great tips for .NET developers
Bonnie DeWitt, October 1, 2006
Great tips for .NET developers
Bonnie DeWitt, November 1, 2006
Great tips for .NET developers
Bonnie DeWitt, December 1, 2006
Great tips for .NET developers
Bonnie DeWitt, January 1, 2007
Great tips for .NET developers
Bonnie DeWitt, February 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers.
Bonnie DeWitt, April 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2007
Good tips for .NET developers.
Bonnie DeWitt, May 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, June 1, 2007
Great tips and tricks for .NET developers.
Bonnie DeWitt, July 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, August 1, 2007
Great tips for .NET developers
Bonnie DeWitt, September 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2008
Great tips for .NET developers selected from the community by Bonnie Berent.
Bonnie DeWitt, April 1, 2008
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, January 1, 2006
Great tips for .NET developers