Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics 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 August 5th, 2009, 10:14 AM
Registered User
 
Join Date: May 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default "Custom" Headertext in a GridView

Greetings all,

Maybe this isn't possible or maybe I am using the wrong control, but does anyone know how to display the HeaderText value in a Gridview control based on a selection made by the user? The Gridview's column data changes and a static HEADERTEXT value becomes incorrect. In other words HEADERTEXT="LEVEL" is incorrect when a selection of "RESIDENCY" is chosen.

<asp:BoundFieldDataField="o0"HeaderText="Level"></asp:BoundField>

I suppose I can get creative with making Boundfilds visible or not, but then the Datafield introduces more complexity on top of that.

Thanks!
 
Old August 5th, 2009, 11:42 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Not sure why the nature of column data should change because the user selects a row.

Maybe I'm not getting the question. :/
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old August 5th, 2009, 11:59 AM
Registered User
 
Join Date: May 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Changing HEADERTEXT in a GRIDVIEW

The default query and resulting summarized Gridview data shows say, enrollment by GENDER (columns) with each row being a different student CLASSIFICATION (rows). Given a checkbox to select say, "ETHNICITY" this alters the SQL and the rows display data for ETHNICITY replacing the row data for CLASSIFICATION. Of course the HEADERTEXT still says ""LEVEL" and should be "ETHNICITY"

I would create the GRIDVIEW dynamically solvingthis problem, but then I run into issues of not being able to export the GRIDVIEW to Excel which is a requirement.

Thanks!
 
Old August 7th, 2009, 10:54 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Really sorry man... I just got back from vacation and I guess I must have some stupid left over from that. I'm having a lot of trouble picturing this in my mind.

Do you have any screenshots of this? Like, before/after? It would help a lot to see what you are doing.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old August 7th, 2009, 12:33 PM
Registered User
 
Join Date: May 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Lee, No problem.

I am not sure how to attach screen shots here, but let me try and clarify my issue/problem.

If a user selects "Race" via a Radio button the following sql executes;
SELECT College as o1, RACE as o2 From .........

If the user selects "Level" from a radio button the following sql executes;
SELECT College as o1, LEVEL as o2 From .........

The results are bound to a GridView and the columns are set to the values used in the sql statements, o1, o2, etc.
<asp:BoundField DataField="o1" HeaderText="College"></asp:BoundField>
<asp:BoundField DataField="o2" HeaderText="Race"></asp:BoundField>

This allows me to use the same GridView for multiple queries based on the selections made by the user as well as keeping the formatting required.

The issue is the HeaderText field in the Gridview. The "o2" field has changed from "RACE" to "LEVEL". I can remove the HeaderText or set ShowHeader = "false", both of which are not helpful. What I would like to do is set the HeaderText for the "o2" field to what was selected by the user. In this case "RACE" or "LEVEL".


So, what I would like to be able to produce is the following;
With the sql statement;
SELECT College as o1, RACE as o2 From .........
Produce the Headertext;
<asp:BoundField DataField="o1"HeaderText="College"></asp:BoundField>
<asp:BoundField DataField="o2"HeaderText="RACE"></asp:BoundField>

the sql statement;
SELECT College as o1, LEVEL as o2 From .........
Produce the Headertext;
<asp:BoundField DataField="o1"HeaderText="College"></asp:BoundField>
<asp:BoundField DataField="o2"HeaderText="LEVEL"></asp:BoundField>

If this still isn't clear don't worry about it. I have found a way where I can dynamically create html table code and bind it to an <asp:Label and produce the desired results. In addition I can export this to Excel easily. If I could export a dynamically created GridView this would all be a mute point.

Thanks!
 
Old August 10th, 2009, 12:10 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Okay, I gotcha. This just seemed like such a simple question that I think I was just trying to make it more complicated than it was.

Using your example, the column whose header text you want to change is the second column.

Let's also assume you have a radio buttom selector like this:

Code:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
   <asp:ListItem Selected="True" Text="Race" Value="Race" />
   <asp:ListItem Text="Level" Value="Level" />
</asp:RadioButtonList>
In the SelectedIndexChanged event (the same event that kicks off the query) you can use the Value text of the selected item to set the header text of the second column...

Code:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
   // do query and databinding here
   GridView1.Columns[1].HeaderText = RadioButtonList1.SelectedValue;
}
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to go back to last position after move mouse by mouse_event Lib "user32" Hoang Excel VBA 0 July 7th, 2009 11:00 PM
Chapter 2 "An attempt to attach an auto-named database for file.." Gredkins BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 4 May 28th, 2009 11:55 PM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM
Chapter-5 on Intents:ContactPickerTester does not show the button "Pick a Contact" sunilm12 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 April 15th, 2009 11:55 AM
How to download Code in "Professional Active Server Page 3.0 " book. renjith0 All Other Wrox Books 2 April 2nd, 2009 05:06 AM





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