473,395 Members | 1,541 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,395 software developers and data experts.

C# question getting data from a GridviewRowDataBound

This is what i'm using and it seems way too complicated!! for finding a data
item.
I hope some one has a better way?
private void fn_setRankingColor(GridViewRow gvr)
{
Label lbl = gvr.FindControl("lbl_RANKINGTODAY") as Label;
if ((Int32)((DataRowView)gvr.DataItem).Row["RN"] ==
(Int32)((DataRowView)gvr.DataItem).Row["RNP"])
{
}
else if ((Int32)((DataRowView)gvr.DataItem).Row["RN"] <
(Int32)((DataRowView)gvr.DataItem).Row["RNP"])
{
lbl.ForeColor = Color.DarkGreen;
lbl.Font.Bold = true;
}
else
{
lbl.ForeColor = Color.DarkRed;
lbl.Font.Bold = true;
}
}

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
Aug 31 '07 #1
3 1705
I would extract the data values into local variables once, and then use the
local variables in the if...else statements.
Looks neater and will give you better performance (because it doesn't have
to retrieve the value for each statement and convert it to an int)

(Note: I've not checked this in VS2005, so I can't guarantee it will compile
and run)
private void fn_setRankingColor(GridViewRow gvr)
{
Label lbl = gvr.FindControl("lbl_RANKINGTODAY") as Label;
int rn = Convert.ToInt32(((DataRowView)gvr.DataItem).Row["RN"]));
int rnp = Convert.ToInt32((((DataRowView)gvr.DataItem).Row["RNP"]));

if( rn == rnp )
{
// Do something
}
else if(rn < rnp )
{
// Do something
}
else
{
// Do something
}
}

HTH

Ged
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:B2**********************************@microsof t.com...
This is what i'm using and it seems way too complicated!! for finding a
data
item.
I hope some one has a better way?
private void fn_setRankingColor(GridViewRow gvr)
{
Label lbl = gvr.FindControl("lbl_RANKINGTODAY") as Label;
if ((Int32)((DataRowView)gvr.DataItem).Row["RN"] ==
(Int32)((DataRowView)gvr.DataItem).Row["RNP"])
{
}
else if ((Int32)((DataRowView)gvr.DataItem).Row["RN"] <
(Int32)((DataRowView)gvr.DataItem).Row["RNP"])
{
lbl.ForeColor = Color.DarkGreen;
lbl.Font.Bold = true;
}
else
{
lbl.ForeColor = Color.DarkRed;
lbl.Font.Bold = true;
}
}

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
Aug 31 '07 #2
ok, did that actually. Thank You. I have to admit i'd perfer not to but i'll
be using the values more than once in the report.

!
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
"Ged" wrote:
I would extract the data values into local variables once, and then use the
local variables in the if...else statements.
Looks neater and will give you better performance (because it doesn't have
to retrieve the value for each statement and convert it to an int)

(Note: I've not checked this in VS2005, so I can't guarantee it will compile
and run)
private void fn_setRankingColor(GridViewRow gvr)
{
Label lbl = gvr.FindControl("lbl_RANKINGTODAY") as Label;
int rn = Convert.ToInt32(((DataRowView)gvr.DataItem).Row["RN"]));
int rnp = Convert.ToInt32((((DataRowView)gvr.DataItem).Row["RNP"]));

if( rn == rnp )
{
// Do something
}
else if(rn < rnp )
{
// Do something
}
else
{
// Do something
}
}

HTH

Ged
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:B2**********************************@microsof t.com...
This is what i'm using and it seems way too complicated!! for finding a
data
item.
I hope some one has a better way?
private void fn_setRankingColor(GridViewRow gvr)
{
Label lbl = gvr.FindControl("lbl_RANKINGTODAY") as Label;
if ((Int32)((DataRowView)gvr.DataItem).Row["RN"] ==
(Int32)((DataRowView)gvr.DataItem).Row["RNP"])
{
}
else if ((Int32)((DataRowView)gvr.DataItem).Row["RN"] <
(Int32)((DataRowView)gvr.DataItem).Row["RNP"])
{
lbl.ForeColor = Color.DarkGreen;
lbl.Font.Bold = true;
}
else
{
lbl.ForeColor = Color.DarkRed;
lbl.Font.Bold = true;
}
}

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes

Aug 31 '07 #3

<Gedwrote in message news:Ov****************@TK2MSFTNGP05.phx.gbl...
>I would extract the data values into local variables once, and then use the
local variables in the if...else statements.
Looks neater and will give you better performance (because it doesn't have
to retrieve the value for each statement and convert it to an int)

(Note: I've not checked this in VS2005, so I can't guarantee it will
compile and run)
private void fn_setRankingColor(GridViewRow gvr)
{
Label lbl = gvr.FindControl("lbl_RANKINGTODAY") as Label;
int rn = Convert.ToInt32(((DataRowView)gvr.DataItem).Row["RN"]));
int rnp = Convert.ToInt32((((DataRowView)gvr.DataItem).Row["RNP"]));
Even better:

DataRow row = ((DataRowView)gvr.DataItem).Row;
int rn = (int)row["RN"];
int rnp = (int)row["RNP"];
if (lbl.Font.Bold = (rn != rnp)) {
lbl.Font.ForeColor = (rn < rnp)? Color.DarkGreen: Color.DarkRed;
}

assuming that the values are boxed integers (they were in the original code)
and don't need the overhead of the Convert.ToInt32 call.

But do you really need all of this?
Label lbl = gvr.FindControl("lbl_RANKINGTODAY") as Label;

Usually FindControl is only used when you don't know the exact control you
want, I suspect in this case you have the Label already stored in a member
variable.

Aug 31 '07 #4

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

Similar topics

5
by: Brian Henry | last post by:
I have a page which reads an article from the database it has 1 text box, 2 dropdown lists, and a longreat HTML text box. I load the information from the database when the page is set to edit mode...
6
by: Brett | last post by:
Not sure what the problem is here... Trying to update from a datagrid to an access database using vb.net... Its not updating the database but Im not getting any errors... Here is my code... ...
4
by: Joe Schmoe | last post by:
All I want to to be able to take a two-column DataReader (One column with the Item ID number, the other with Item Description text) and load it into a Windows Forms ComboBox (Set to DropDownList...
0
by: sags | last post by:
Hi , Iam a new uesr of this group. I have a small doubt . Iam using the code mentioned below to retrive the data from tab delimited text file ., but Iam getting all the columns of the text file...
4
by: R.Manikandan | last post by:
Hi In my code, one string variable is subjected to contain more amount of characters. If it cross certain limit, the string content in the varabile is automatically getting truncated and i am...
5
by: Archana | last post by:
Hi all, I am having application where i am downloading xml content using webrequest. my code is as below HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL); HttpWebResponse...
3
by: JohnGos | last post by:
Since around 10th May (a couple of days after the recent IE autoupdate), a web application which has worked without problem for several years has developed intermittent problems with data posted from...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
1
imrosie
by: imrosie | last post by:
Please help with this one,,,,,I've been trying everything in my arsenal to fix this one. I'm stumped.... I"ve got a unbound combo box (customername) that has two events (on click); AfterUpdate and...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.