Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
  #1 (permalink)  
Old August 16th, 2012, 09:48 PM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default changing column header text?

Hi, i was so grateful to learn new things like LINQ to Entity and i use it a lot and incorporate it on my programming practice.

My problem is how can i change the column header text programmatically? when i use LINQ to Entity, the text in the column header appears as "Item" i tried different ways but all of them only resulted in error. can i change the column header text without using datasource controls, only with LINQ to ENTITY? thanks.
  #2 (permalink)  
Old August 17th, 2012, 01:51 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can set them up in markup, just as you could do when using a Data Source control.

To do it at run-time, you can access a property like Columns to change the name. You didn't mention which data control you're using, but if you were using a GridView you could do something like this:

Code:
GridView1.Columns[0].HeaderText = "Some new header";
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
rmanapul (August 21st, 2012)
  #3 (permalink)  
Old August 21st, 2012, 08:13 PM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

oh sorry i forgot to mention the name but yes, it's gridview im using. you will have to change it in the markup and not in the code-behind?
  #4 (permalink)  
Old August 22nd, 2012, 03:21 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,
Quote:
you will have to change it in the markup and not in the code-behind?
I am not sure I understand this. Didn't my post mention both?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #5 (permalink)  
Old August 22nd, 2012, 03:33 AM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

i tried to do it in the code behind but when i code it the .HeaderText property does not appear and it results to error. do i have to import anything before i use it? im using VB as my language
  #6 (permalink)  
Old August 22nd, 2012, 03:42 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I guess that's near impossible to say without seeing the source code and the exact error message.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #7 (permalink)  
Old August 23rd, 2012, 08:48 PM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

here is the complete code of the program:


Code:
Imports AlumniTblModel
Partial Class Management_Sample
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Using myEntities As New AlumniTblEntities

            Dim allProvinces = From province In myEntities.ProvinceTbls
                               Order By province.Province
                               Select province.Province




            ProvinceGrid.DataSource = allProvinces
            ProvinceGrid.DataBind()
            ProvinceGrid.Columns[0].HeaderText = "Provinces"

        End Using
    End Sub
End Class
when i typed the HeaderText, the intellisense does not show. and the Text "Provinces" does not appear as red color it's supposed to appear as red colored i think? can you also help me how to do paginating and sorting (when the header title is clicked) in this gridview programmatically? where you can only show 5 or 10 items per page.

Last edited by rmanapul; August 23rd, 2012 at 08:51 PM..
  #8 (permalink)  
Old August 24th, 2012, 02:28 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The example I posted was C#. Since you're using VB, you need parenthesis instead of brackets:

Code:
ProvinceGrid.Columns(0).HeaderText = "Provinces"
For paging, look at Skip and Take. However, in this case, since you're doing straight forward LINQ queries, I would suggest the EntityDataSource instead as it'll take care off all of this.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #9 (permalink)  
Old August 24th, 2012, 03:25 AM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

When i tried to run the application, visual studio provided me with this message:

"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"

do i need to import something???
  #10 (permalink)  
Old August 24th, 2012, 03:41 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you using auto generated columns? If so, they are not added the Columns collection which will remain at zero, causing this error. You can do it like this instead:

Code:
ProvinceGrid.HeaderRow.Cells(0).Text = "Provinces"
May I ask what you're trying to accomplish? Is there any reason why you're not explicitly defining the columns in the GridView and instead rely on run-time discovery? Also any reason for not using the EntityDataSource to handle binding, paging and sorting for you?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; August 24th, 2012 at 04:17 AM.. Reason: Fixed type
The Following User Says Thank You to Imar For This Useful Post:
rmanapul (August 24th, 2012)




Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.Net 2008 Print DataGridView (Text Wrap top header column and lock in width) remya1000 Visual Studio 2008 1 February 14th, 2012 12:56 AM
Export Column Header to Text File in SSIS lavisualstudio BOOK: Professional Microsoft SQL Server 2008 Integration Services ISBN: 978-0-470-24795-2 0 March 13th, 2010 09:55 PM
Runtime Column Header Text vinod_yadav1919 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 November 29th, 2008 01:53 AM
Changing the "From" header when sending email rinventive BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 May 23rd, 2006 03:56 PM
changing image/logo in report header h_haviv Crystal Reports 1 February 27th, 2005 07:59 PM





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