 |
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 24th, 2012, 04:07 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
sir when i used .HeaderText an error says "HeaderText is not a member of System.Web.Ui.WebControls.TableCell." i changed it to .Text and it worked. thanks for the code! Now it's running :)
|
|

August 24th, 2012, 04:18 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You're correct. My mistake. I updated the original post as well.
Quote:
|
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?
|
Want to comment on this? I am wondering why you're doing what you're doing...
Imar
|
|

August 28th, 2012, 08:45 PM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
I dont know how to control the binding in the datasource controls using if-else. is there a way on how to manipulate the datasource controls programmatically? Im using the things i learned from your book in creating an Online Alumni System for our school. Our College hired me as their web developer and web administrator. thanks for the things i learned from your book and i hope you publish more in the future :)
|
|

August 29th, 2012, 04:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
is there a way on how to manipulate the datasource controls programmatically?
|
Yes, but you need to provide more info about what it is you want to do.
Cheers,
Imar
|
|

August 29th, 2012, 04:29 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
for example you can program the datasource control to bind to a specific table based on the arguments in the if-else statement. is that possible?
|
|

August 29th, 2012, 04:30 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am not sure I get this. Can you describe the use case? Why does this have to be so dynamic? I am not saying you don't need this, but you may be making this more complicated that needed.
Cheers,
Imar
|
|

August 29th, 2012, 04:47 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
for example,
using values to change the contents of gridview. i can do it without the help of datasource control
Code:
If Province_Ddl.SelectedValue = "Province1" Then
Dim Province1Municipality = From city In myEntities.CityTbls
Where city.Province = "Province1"
Order By city.City
Select city.City
cityGridView.DataSource = Province1Municipality
cityGridView.DataBind()
ElseIf Province_Ddl.SelectedValue = "Province2" Then
Dim Province2Municipality = From city In myEntities.CityTbls
Where city.Province = "Province2"
Order By city.City
Select city.City
cityGridView.DataSource = Province2Municipality
cityGridView.DataBind()
ElseIf Province_Ddl.SelectedValue = "Province3" Then
Dim Province3Municipality = From city In myEntities.CityTbls
Where city.Province = "Province3"
Order By city.City
Select city.City
cityGridView.DataSource = Province3Municipality
cityGridView.DataBind()
.
.
.
.
.
.
End If
by the way, our country has more than 75 provinces so i handcoded and copy-pasted them one by one.
|
|

August 29th, 2012, 05:26 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
by the way, our country has more than 75 provinces so i handcoded and copy-pasted them one by one.
|
Really? Wow! What a nightmare that must be if you ever want to change something.
What about this:
Code:
Dim ProvinceMunicipalities = From city In myEntities.CityTbls
Where city.Province = Province_Ddl.SelectedValue
Order By city.City
Select city.City
cityGridView.DataSource = ProvinceMunicipalities
cityGridView.DataBind()
Not it works for all 75 of them, regardless of what you choose in the DDL.
To make this even easier, set up the data source for the GridView to use the SelectedValue of the DropDownList. This way, you can accomplsih the exact same thing without manual coding and just a few server controls.
You find an example that demonstrates exactly this (using Genres and Reviews) on page 446 and further in the section "Filtering Data".
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 29th, 2012, 07:27 PM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
wow thanks. i didn't know that controls can also be called in LINQ queries lol. im going to try that :)
Last edited by rmanapul; August 29th, 2012 at 10:00 PM..
|
|
 |
|