 |
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
|
|
|
|

August 16th, 2012, 09:48 PM
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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.
|

August 17th, 2012, 01:51 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

August 21st, 2012, 08:13 PM
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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?
|

August 22nd, 2012, 03:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

August 22nd, 2012, 03:33 AM
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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
|

August 22nd, 2012, 03:42 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I guess that's near impossible to say without seeing the source code and the exact error message.
Cheers,
Imar
|

August 23rd, 2012, 08:48 PM
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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..
|

August 24th, 2012, 02:28 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

August 24th, 2012, 03:25 AM
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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???
|

August 24th, 2012, 03:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
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:
|
|
|
 |
|