Wrox Programmer Forums
|
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 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 April 16th, 2009, 01:54 PM
Authorized User
 
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
Default CheckBoxes for CustomGridView

Yesterday I set out to do two things with the CustomGridView.

First, I wanted to show the grid even when there was no data (similar to what the GridView does), but I also wanted the headers to show (something the GridView does not do).

That was easily accomplished by overriding CreateChildControls - check out http://dotnetslackers.com/GridView/r...ta_Exists.aspx if you're interested.

The scond one, adding a CheckBox, proved more challenging. Not creating the field, but setting it to the right value on the RowDataBound event.

I added the following function to CustomGridView.cs:

Code:
public void AddBoundCheckBox(string dataField, string headerText, string sortExpression)
{
   CheckBoxField cbf = newCheckBoxField();
 
   if (dataField != "")
        cbf.DataField = dataField;
   if (headerText != "")
        cbf.HeaderText = headerText;
   if (sortExpression != "")
        cbf.SortExpression = sortExpression;
 
   Columns.Add(cbf);
}
Getting the value set was a lot more challenging (for me). Here's what I ultimately came up with (variable names changed from my code) in the RowDataBound event handler:

Code:
((CheckBox)e.Row.Cells[COL_INDEX_CONST].Controls[0]).Checked = ((baseEO)e.Row.DataItem).SomeBooleanProperty;
This works....but I'm wondering if there's an easier/better way to do this?

Tim
 
Old April 20th, 2009, 11:27 PM
Wrox Author
 
Join Date: Jan 2009
Posts: 73
Thanks: 0
Thanked 7 Times in 7 Posts
Default

Hi Tim,
You could also just create the checkbox in the RowDataBound event and add the control to the cell similar to how the Edit and Delete links get added. Either way will work and really it comes down to what you are more comfortable with.
Vince





Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview with checkboxes kgaughan1 ASP.NET 2.0 Professional 0 February 11th, 2007 11:31 PM
Using Checkboxes in datagrid ractim General .NET 2 September 21st, 2004 05:14 AM





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