473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Gridview - conditional formatting

Hey,

In order to customise rows on my gridview control, I've some code in the
RowDataBound event, that works on each row, altering it's attributes..

for example I have:

If gvResults.DataKeys.Item(e.Row.RowIndex).Values.Ite m(1).ToString() =
"True" Then

e.Row.BackColor = Drawing.Color.LightGray
e.Row.ForeColor = Drawing.Color.Black
e.Row.Cells(1).Enabled = False

which tests a rows' hidden value (in a datakey) and acts accordingly on
the row... cells(1) holds a button.

Now I wish to do more to the row than just enable/disable it and change
colours.. supposing I wanted to change the text on the button - is this
possible?

If I do:
e.Row.Cells(1).Text = "Provide contact information"

it replaces the whole button with just some text.. how can I access the
buttons' .text property?

Cheers,
Chris
Feb 9 '06 #1
8 9077
Chris,

You need to get the button out of the row.

Dim RowButton as Button = CType(e.Row.FindControl("[ButtonId]"), Button)

RowButton.Text = "Provide contact information"
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Not Me" <no****@zxy.blah.org> wrote in message
news:ds**********@ucsnew1.ncl.ac.uk...
Hey,

In order to customise rows on my gridview control, I've some code in the
RowDataBound event, that works on each row, altering it's attributes..

for example I have:

If gvResults.DataKeys.Item(e.Row.RowIndex).Values.Ite m(1).ToString() =
"True" Then

e.Row.BackColor = Drawing.Color.LightGray
e.Row.ForeColor = Drawing.Color.Black
e.Row.Cells(1).Enabled = False

which tests a rows' hidden value (in a datakey) and acts accordingly on
the row... cells(1) holds a button.

Now I wish to do more to the row than just enable/disable it and change
colours.. supposing I wanted to change the text on the button - is this
possible?

If I do:
e.Row.Cells(1).Text = "Provide contact information"

it replaces the whole button with just some text.. how can I access the
buttons' .text property?

Cheers,
Chris

Feb 9 '06 #2
S. Justin Gengo [MCP] wrote:
Chris,

You need to get the button out of the row.

Dim RowButton as Button = CType(e.Row.FindControl("[ButtonId]"), Button)

RowButton.Text = "Provide contact information"


Super :)

Cheers,
Chris
Feb 10 '06 #3
Not Me wrote:
S. Justin Gengo [MCP] wrote:
Chris,

You need to get the button out of the row.

Dim RowButton as Button = CType(e.Row.FindControl("[ButtonId]"), Button)

RowButton.Text = "Provide contact information"


Super :)


And as per usual... I'm a tad hasty and need my hand held a little
further down the path!

The button comes from:

<asp:ButtonField Text="View Record" ButtonType="Button"
CommandName="select" />

....in the gridview columns section, so what would the buttonID be called?

Cheers for the help,
Chris

Feb 10 '06 #4
Chris,

Ok, that is a bit different. I didn't know you were using an autogenerated
button. But things should be very similar. Instead of referring to the
button by its id refer to it by its index. And I think you'll find the
select button is actually a link button.

Dim RowButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Not Me" <no****@zxy.blah.org> wrote in message
news:ds**********@ucsnew1.ncl.ac.uk...
Not Me wrote:
S. Justin Gengo [MCP] wrote:
Chris,

You need to get the button out of the row.

Dim RowButton as Button = CType(e.Row.FindControl("[ButtonId]"), Button)

RowButton.Text = "Provide contact information"


Super :)


And as per usual... I'm a tad hasty and need my hand held a little further
down the path!

The button comes from:

<asp:ButtonField Text="View Record" ButtonType="Button"
CommandName="select" />

...in the gridview columns section, so what would the buttonID be called?

Cheers for the help,
Chris

Feb 11 '06 #5
S. Justin Gengo [MCP] wrote:
Chris,

Ok, that is a bit different. I didn't know you were using an autogenerated
button. But things should be very similar. Instead of referring to the
button by its id refer to it by its index. And I think you'll find the
select button is actually a link button.

Dim RowButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)


Thanks (again!), I've found the button, but it's type is
DataControlButton, and casting it as a Linkbutton gives a 'cannot cast'
error..

(Unable to cast object of type
'System.Web.UI.WebControls.DataControlButton' to type
'System.Web.UI.WebControls.LinkButton'.)

I can't find any information on DataControlButton anywhere!

Cheers,
Chris
Feb 14 '06 #6
Chris,

Good to know that it's a datacontrol button. Just cast it as that and you
should be all set!

Sincerely,

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Not Me" <no****@zxy.blah.org> wrote in message
news:ds**********@ucsnew1.ncl.ac.uk...
S. Justin Gengo [MCP] wrote:
Chris,

Ok, that is a bit different. I didn't know you were using an
autogenerated button. But things should be very similar. Instead of
referring to the button by its id refer to it by its index. And I think
you'll find the select button is actually a link button.

Dim RowButton As LinkButton = CType(e.Row.Cells(0).Controls(0),
LinkButton)


Thanks (again!), I've found the button, but it's type is
DataControlButton, and casting it as a Linkbutton gives a 'cannot cast'
error..

(Unable to cast object of type
'System.Web.UI.WebControls.DataControlButton' to type
'System.Web.UI.WebControls.LinkButton'.)

I can't find any information on DataControlButton anywhere!

Cheers,
Chris

Feb 15 '06 #7
S. Justin Gengo [MCP] wrote:
Chris,

Good to know that it's a datacontrol button. Just cast it as that and you
should be all set!


eeeh sorry, it threw me that using the datacontrolbutton gives errors in
my (beta) of visual studio (type not defined), I couldn't find mention
of the control in msdn either.

However when running on an IIS server using the release edition of .net
2.0, it must know what a datacontrolbutton is.. as the error I get is:
'System.Web.UI.WebControls.DataControlButton' is not accessible in this
context because it is 'Private'.

....just when I thought it was a nice thing that asp 2 writes half the
code for you :) any (more) ideas?

Cheers,
Chris

Feb 17 '06 #8
Chris,

Ok, sorry I was away for a while here.

It looks as if you won't be able to use the built in button that's
automatically generated (big news eh?). But you should be able to do the
same thing by placing your own button column in the grid. You can do this
"codeless" by editing the grid's columns and dropping in a command button.
There you'll be able to set the command buttons to show or not to show and
they will be accessible because they will be set to public.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Not Me" <no****@zxy.blah.org> wrote in message
news:dt**********@ucsnew1.ncl.ac.uk...
S. Justin Gengo [MCP] wrote:
Chris,

Good to know that it's a datacontrol button. Just cast it as that and you
should be all set!


eeeh sorry, it threw me that using the datacontrolbutton gives errors in
my (beta) of visual studio (type not defined), I couldn't find mention of
the control in msdn either.

However when running on an IIS server using the release edition of .net
2.0, it must know what a datacontrolbutton is.. as the error I get is:
'System.Web.UI.WebControls.DataControlButton' is not accessible in this
context because it is 'Private'.

...just when I thought it was a nice thing that asp 2 writes half the code
for you :) any (more) ideas?

Cheers,
Chris

Feb 24 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
4
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
8
by: Dimitri Furman | last post by:
Given: Access 2002/2003 A subform in datasheet or continuous view, placed on a tab page (this last may or may not matter) Conditional formatting applied to some controls on the subform - format...
2
by: Von Bailey | last post by:
I have a form where the conditional formatting is set on some fields to bold if certain conditions are met. However, when the conditions are met some of the data that is to bold is either not...
1
by: GGerard | last post by:
Hello Is there a way to use a variable in the Conditional Formatting of a Textbox? Example : I want the background of a textbox in a continuous form to change color when the value of...
1
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do...
2
by: Jim in Arizona | last post by:
Using a GridView or other data reading control (gridview, datagrid, datalist), how can I do conditional formatting on the results pulled from an access database? As an exampe, use a sql statement...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
4
by: midlothian | last post by:
Hello, I have conditional formatting set up on a subform based on a calculated value in the underlying query. For instance, if Sales are >$1000, the query displays "Yes," otherwise it displays...
2
by: tomh2099 | last post by:
Hi, Hi, I have an ASP.NET 2005 application (using VB) with a GridView control that needs to have the last 5 or 6 rows in Bold or maybe some other special formatting. Most of the rows show...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.