Advertisement

05.06.2008 at 06:34PM PDT, ID: 23381425
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Need to create a custom gridview with different cell colors
Tags: VB
Have a stored procedure that returns the results in attached excel file. Need to have this stored procedure fill a gridview or table. As shown in attached excel file there are some columns that have the same name just the word HOLD added to the beginning. These columns need to indicate the color of the cell in the proceeding column. For instance holdArrival_Date value = 1 will indicate the Arrival Date cell to be green, if it were 0 then it would be red. Each user has different setting and thus produces different columns so the code will need to fill in the headers also removing the columns that start with HOLD.  

The first 2 columns are the only 2 that stay the same, the shipmentID should not be shown but should allow for a link when some one clicks on the CLID and this is the ID number that is posted to the next page.

Need the code in some type of function as its will be used many times though-out the site and twice on one page.  The stored procedure requires 2 values that come from session variables.

Working with ASP.NET in VB
Attachments:
 
SP Results
 
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: crundle
Solution Provided By: naspinski
Participating Experts: 2
Solution Grade: B
Views: 7
Translate:
Loading Advertisement...
05.06.2008 at 08:19PM PDT, ID: 21512965

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 08:21PM PDT, ID: 21512975

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 08:27PM PDT, ID: 21512991

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 08:29PM PDT, ID: 21512999

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 08:37PM PDT, ID: 21513032

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 09:01PM PDT, ID: 21513106

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 09:07PM PDT, ID: 21513121

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 12:50PM PDT, ID: 21519761

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 01:15PM PDT, ID: 21519989

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 04:47PM PDT, ID: 21521307

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 06:12PM PDT, ID: 21521642

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 07:15PM PDT, ID: 21521874

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 07:32PM PDT, ID: 21521926

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 08:41PM PDT, ID: 21522168

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 09:04PM PDT, ID: 21522257

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 03:24PM PDT, ID: 21536755

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.06.2008 at 08:19PM PDT, ID: 21512965

Rank: Master

Hello,

You need to use RowDataBound event of your gridview and do something like that:


      protected void GridView1_RowDataBound( object sender, GridViewRowEventArgs e )
      {
            GridViewRow row = e.Row;

            if( row.RowType == DataControlRowType.DataRow )
            {
                  if( row.Cells[ 2 ].Text == "1" )
                        row.Cells[ 1 ].BackColor = Color.Green;

                  else if( row.Cells[ 2 ].Text == "0" )
                        row.Cells[ 1 ].BackColor = Color.Red;

                  else
                        row.Cells[ 1 ].BackColor = Color.Gray;

            }
      }

As for visible, not visible, just play with your "Edit Columns" settings for your GridView. You hide columns, you can set hyperlink columns to pass databound values etc. The GridView is quite flexible control ;)

Good luck,
Yurich
 
05.06.2008 at 08:21PM PDT, ID: 21512975

Rank: Master

I have to do something like this before.  What you are going to do is pass a value that wil run a switch statement and return the proper color, here is an example

Inside a gridview:
<asp:TemplateField>
    <ItemTemplate>
        <div style="Background:<%# getColor(Eval("id")) %>;" >
            <asp:Label runat="server" Text='<%# Eval("id") %>' />
        </div>
    </ItemTemplate>
</asp:TemplateField>

Notice getColor and the parameter that is passed (id is an integer)
And the function, this will make the cell red if the id is 1-5, blue if it anything else.  I know that this is not exactly what you want, but it shows what you need to do.  You can also use it will a classes or anything else.
1:
2:
3:
4:
5:
6:
7:
8:
    Public Function getColor(ByVal input As Integer) As String
        Select Case input
            Case 1 To 5
                Return "Red"
            Case Else
                Return "Blue"
        End Select
    End Function
Open in New Window
 
05.06.2008 at 08:27PM PDT, ID: 21512991

Rank: Master

2 naspinski: doesn't look like a simplest way of doing it :\
 
05.06.2008 at 08:29PM PDT, ID: 21512999

Rank: Master

Just a different method, which I think is easier :)
 
05.06.2008 at 08:37PM PDT, ID: 21513032

Rank: Master

it's more original, that's for sure ;)
 
05.06.2008 at 09:01PM PDT, ID: 21513106
Sorry guys, I'm very new to asp.net can you provide a full set of code on how I would use your ideas? Also how could I replace the "_" in the column headers?
I attached my current gridview code.

I was thinking I would have to loop though both columns and rows building one at a time.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CLLDdataSQLConnectionString %>" 
        SelectCommand="test2" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter DefaultValue="2" Name="ClientID" Type="Int32" />
            <asp:Parameter DefaultValue="container" Name="ShipmentType" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    
        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
        </asp:GridView>
    
    </div>
 
    </form>
</body>
</html>
Open in New Window
 
05.06.2008 at 09:07PM PDT, ID: 21513121

Rank: Master

for mine, stick this into your gridview:

<asp:TemplateField>
    <ItemTemplate>
        <div style="Background:<%# getColor(Eval("holdArrival_Date")) %>;" >
            <asp:Label runat="server" Text='<%# Eval("holdArrival_Date") %>' />
        </div>
    </ItemTemplate>
</asp:TemplateField>

and this in your code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
    Public Function getColor(ByVal input As Integer) As String
        Select Case input
            Case 1
                Return "Red"
            Case 0
                Return "Green"
            Case Else
                Return String.Empty
        End Select
    End Function
Open in New Window
Accepted Solution
 
05.07.2008 at 12:50PM PDT, ID: 21519761
Yurich: I'm working with VB not C# and can not edit columns as the columns are different every time

naspinski: I tried what you said and it does not work (error is shown below). The second issued is that I can not declare the field "holdArrival_Date" as this need to work on many different columns. Please see the excel file attached at the beginning of this posting

Error: 'System.Web.UI.WebControls.GridView' does not have a public property named 'TemplateField'.

Need code that goes though the dataset, if there is a "HOLD" + field name then it changes the color of the field name background and removes the hold column. I have attached what the table should look like after the process.
 
dataset results and finished look
 
 
05.07.2008 at 01:15PM PDT, ID: 21519989

Rank: Master

Quote: "Yurich: I'm working with VB not C# and can not edit columns as the columns are different every time" - that was funny :)

You can do in VB 95% if not even more of what you can do in C# and that simple exercise you can do for sure.

You columns can't be different every time - you're loading from the same database table, aren't you? And even if they're, you can use a column name, not an index.

I'll see if I can VB code for you to do it today...

Good luck,
Yurich
 
05.07.2008 at 04:47PM PDT, ID: 21521307

Rank: Master

Error: 'System.Web.UI.WebControls.GridView' does not have a public property named 'TemplateField'.

That is because it has to be embedded within 2 <Columns> tags:

<Gridview ... >
  <Columns>
    <ItemTemplate>
    </ItemTemplate>
  </Columns>
</Gridview>
 
05.07.2008 at 06:12PM PDT, ID: 21521642
Solution to the problem below
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            For j = 0 To e.Row.Cells.Count - 1
                If IsNumeric(e.Row.Cells(j).Text) Then
                    If e.Row.Cells(j).Text = 1 Then
                        e.Row.Cells(j - 1).BackColor = System.Drawing.Color.Maroon
                    End If
                End If
            Next
        End If
    End Sub
Open in New Window
 
05.07.2008 at 07:15PM PDT, ID: 21521874

Rank: Master

Well, and isn't it what I was telling you?? Using RowDataBound event?? I do object about JUST closing this question.
 
05.07.2008 at 07:32PM PDT, ID: 21521926
Yurich: Since you have an objection, answer the question in its entirety for the full points. You pointed me in a direction and thats why I awarded you 100 Points. You were and are missing parts to the solution.
 
05.07.2008 at 08:41PM PDT, ID: 21522168

Rank: Master

Well first, I don't see any points awarded to me, it's said you requested to close the question with points refunded. Second, all you had to do is implement to some particulars specific to your data format, i gave you a working sample, which you applied to your particular situation.

Amazing how people can be mingy and ungreatful after they got helped - you asked for help, you got two working samples, due to your lack of experience you couldn't use them at the first time and now you're arguing if you were helped at all. We saved you time and money and what am I getting?? You're telling me off!! If it was in any consultancy, I (or any other programmer-consultant) would write this code for your for 5 minutes and you'd get charged for a couple of hundred bucks, and that woud be your full answer. Unbelievable.
 
05.07.2008 at 09:04PM PDT, ID: 21522257
Yurich:
      I see you are very troubled about this. First off, you have yet to complete the question proposed at the beginning (which was valued at 500 points). Second the solution did not even come close to the problem, all be it you advised to look at RowDataBound (thus the reason for the 100 Points awarded). The program language was incorrect, your response did not address the fact that there are multiple columns that need to have the color changed, did not take into account removing certain columns, did not create the link on the first column.  

You were provided a fair number of points for advising to look at RowDataBound.Please move on from this question, from the start of this posting you have been a very rude person not just to me but others and in no way am I telling you off, I did offer you 1/5 of the initial offer for your guidance. Answer the full question and I will award you the full points.

No response is required unless you are answering the question. If you have an issue with me, please take it up with the mediator
 
05.09.2008 at 03:24PM PDT, ID: 21536755

Rank: Master

I do object
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628