Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 9th, 2005, 07:25 AM
Registered User
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default help required for using DataGrid in asp.net

Hi,

I want to display the details of Datagrid Headertext and Datavalue whatever has been bound with Datagrid columns when I click on a button by using for loop in asp.net.I was able to show the headertext but not able to show the Datafield.i have used the following code.

Sub Button7_Click(sender As Object, e As EventArgs)
dim i as integer
dim j as integer
j=DataGrid1.Columns.count-1
for i = 1 to j
Response.write(DataGrid1.Columns.item(i).HeaderTex t)
Response.write(DataGrid1.Columns(i).DataField)
Next
End sub
I am getting error on "Response.write(DataGrid1.Columnsi).DataField) "
Please help me.


 
Old June 9th, 2005, 08:44 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

And that error was?

-Peter
 
Old June 9th, 2005, 09:26 AM
Registered User
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,
I am getting this error

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30456: 'DataField' is not a member of 'System.Web.UI.WebControls.DataGridColumn'.


 
Old June 9th, 2005, 09:36 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Aha, yes indeed that is correct. DataField is not a member of that class. However, it IS a member of derived classes that provide the ability to bind to a column in the underlying data bound to a grid such as the BoundColumn class.

When you iterate thru the columns collection of the datagrid, you get DataGridColumn objects, not their final column class types (BoundColumn, TemplateColumn, etc.). So you'll need to test each DataGridColumn you iterate thru to see if it is of type BoundColumn (or which ever other types support DataField), then you can emit that field's value.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Proxy Authentication Required in ASP.Net appln. rajbiswas76 General .NET 2 March 2nd, 2007 09:12 AM
vb.net asp.net DataGrid krantips VS.NET 2002/2003 0 June 28th, 2006 01:22 AM
help required in datagrid dynamic template column govind ASP.NET 1.x and 2.0 Application Design 2 January 4th, 2006 11:32 AM
Help required with ASP .NET in Dreamweaver MX CFerthorney Dreamweaver (all versions) 3 September 7th, 2003 11:27 AM





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