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

ok,asking for C# help again

i have the following code that deos not work: I have done this in vb wher i
include an item as object and then am able to find it correctly. Not working
here!!!

1. trying to just find the control to get its type: if
((gvr.FindControl(objPosNeg1) == "System.Web.UI.WebControls.HyperLink"))

i'll start here and thanks
CODE:

void fn_setLBLToBoldLOCAL(GridViewRow gvr, object objPosNeg1, object
objPosNeg2, string szPosNeg)
{

if (((DataRowView)gvr.DataItem).Row[szPosNeg] == "Y")
{
if ((gvr.FindControl(objPosNeg1) ==
"System.Web.UI.WebControls.HyperLink"))
{
object obj = gvr.FindControl(objPosNeg1);
((HyperLink)(obj)).Font.Bold = true;
}
if ((gvr.FindControl(objPosNeg2).GetType.ToString ==
"System.Web.UI.WebControls.Label"))
{
object obj = gvr.FindControl(objPosNeg2);

((Label)(obj)).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 30 '07 #1
6 1163
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:8E**********************************@microsof t.com...
if ((gvr.FindControl(objPosNeg2).GetType.ToString ==
"System.Web.UI.WebControls.Label"))
You've forgotten the parentheses at the end of ToString
if ((gvr.FindControl(objPosNeg1) ==
"System.Web.UI.WebControls.HyperLink"))
You've forgotten .GetType.ToString() before the ==
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 30 '07 #2
Use "is"

if (someObject is System.Web.UI.WebControls.HyperLink)
{
}

Note there are no quotes around the type.

"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:8E**********************************@microsof t.com...
>i have the following code that deos not work: I have done this in vb wher i
include an item as object and then am able to find it correctly. Not
working
here!!!

1. trying to just find the control to get its type: if
((gvr.FindControl(objPosNeg1) == "System.Web.UI.WebControls.HyperLink"))

i'll start here and thanks
CODE:

void fn_setLBLToBoldLOCAL(GridViewRow gvr, object objPosNeg1, object
objPosNeg2, string szPosNeg)
{

if (((DataRowView)gvr.DataItem).Row[szPosNeg] == "Y")
{
if ((gvr.FindControl(objPosNeg1) ==
"System.Web.UI.WebControls.HyperLink"))
{
object obj = gvr.FindControl(objPosNeg1);
((HyperLink)(obj)).Font.Bold = true;
}
if ((gvr.FindControl(objPosNeg2).GetType.ToString ==
"System.Web.UI.WebControls.Label"))
{
object obj = gvr.FindControl(objPosNeg2);

((Label)(obj)).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 30 '07 #3
Also, always check to see if the FindControl returns a null first, otherwise
you'll get a nasty error.

if ((gvr.FindControl(objPosNeg1) != null) &&
(gvr.FindControl(objPosNeg1).GetType().ToString() ==
"System.Web.UI.WebControls.HyperLink")))
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:8E**********************************@microsof t.com...
>i have the following code that deos not work: I have done this in vb wher i
include an item as object and then am able to find it correctly. Not
working
here!!!

1. trying to just find the control to get its type: if
((gvr.FindControl(objPosNeg1) == "System.Web.UI.WebControls.HyperLink"))

i'll start here and thanks
CODE:

void fn_setLBLToBoldLOCAL(GridViewRow gvr, object objPosNeg1, object
objPosNeg2, string szPosNeg)
{

if (((DataRowView)gvr.DataItem).Row[szPosNeg] == "Y")
{
if ((gvr.FindControl(objPosNeg1) ==
"System.Web.UI.WebControls.HyperLink"))
{
object obj = gvr.FindControl(objPosNeg1);
((HyperLink)(obj)).Font.Bold = true;
}
if ((gvr.FindControl(objPosNeg2).GetType.ToString ==
"System.Web.UI.WebControls.Label"))
{
object obj = gvr.FindControl(objPosNeg2);

((Label)(obj)).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 30 '07 #4
On 30 Aug, 16:32, WebBuilder451
<WebBuilder...@discussions.microsoft.comwrote:
i have the following code that deos not work: I have done this in vb wheri
include an item as object and then am able to find it correctly. Not working
here!!!

1. trying to just find the control to get its type: if
((gvr.FindControl(objPosNeg1) == "System.Web.UI.WebControls.HyperLink"))

i'll start here and thanks
CODE:

void fn_setLBLToBoldLOCAL(GridViewRow gvr, object objPosNeg1, object
objPosNeg2, string szPosNeg)
{

if (((DataRowView)gvr.DataItem).Row[szPosNeg] == "Y")
{
if ((gvr.FindControl(objPosNeg1) ==
"System.Web.UI.WebControls.HyperLink"))
{
object obj = gvr.FindControl(objPosNeg1);
((HyperLink)(obj)).Font.Bold = true;
}
if ((gvr.FindControl(objPosNeg2).GetType.ToString ==
"System.Web.UI.WebControls.Label"))
{
object obj = gvr.FindControl(objPosNeg2);

((Label)(obj)).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
Remember to deal with the condition where there is no DataRowView data
- when ((DataRowView)gvr.DataItem is null otherwise someone will
scream
at you when they have to debug your code - and it isn't nice being
screamed at. Something like this:

DataRowView drv = gvr.DataItem as DataRowView;
if (drv != null && drv.Row[szPosNeg] == "Y") {
...
}
else {
...
}

You'll probably get better C# answers are:
news:microsoft.*public.*dotnet.*languages.*csharp

Aug 30 '07 #5
Thank you, i'll be making simple mistakes for the next few weeks while i pick
CS up.
(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
"Mark Rae [MVP]" wrote:
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:8E**********************************@microsof t.com...
if ((gvr.FindControl(objPosNeg2).GetType.ToString ==
"System.Web.UI.WebControls.Label"))

You've forgotten the parentheses at the end of ToString
if ((gvr.FindControl(objPosNeg1) ==
"System.Web.UI.WebControls.HyperLink"))

You've forgotten .GetType.ToString() before the ==
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 30 '07 #6
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:86**********************************@microsof t.com...
Thank you, i'll be making simple mistakes for the next few weeks while i
pick
CS up.
No worries - everyone started off as a newbie... :-)
I find C# totally way cooler than vb and there''s no go''n back!!!
You'll get no argument about that from me... :-) Of course, other than the
obvious syntactical differences, VB.NET is just as good as C# because both
languages compile down to the same thing... C# supports unsafe code aka
pointers, but that's about the only real difference...

Back in early 2002, I'd made a good living using almost nothing else but
Basic and its various derivatives, right back from the QuickBasic days
through VB, VBA, WordBasic, AccessBasic, VBScript etc... The only exception
to that was JavaScript...

Then I got my first beta of Visual Studio.NET and had a look at some of the
C# examples and, in less than a day, never wanted to use anything else!

However, I'd say it was *at least* six months before I felt I was even
partly up to speed with it, so don't give up... :-)
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 30 '07 #7

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

Similar topics

0
by: ThunderMusic | last post by:
Hi, I'm trying to install VS.NET 2003 and it keeps asking me to reboot the computer for installing the first step. After rebooting, I try to install the first step, then it tells me again an...
0
by: chrisben | last post by:
Hi, Developing Env: .NET Studio in C#, windows 2000 target: a COM object used for excel user (RTD) I have no problem to compile and run the project in my machine. The excel is working great...
258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
6
by: Andy | last post by:
.... as I know the answer will be so simple, but here goes... I cannot creating a new asp.net projects in VS2003 in a directory other than the default suggested directory (i.e....
3
by: Bill Nguyen | last post by:
Once applied the latest security patches from Microsoft, OL on our VB app client machines keep popping up dialog box asking for permission to send mail using OL. Is there anyway to by pass this...
2
by: Don | last post by:
I've asked before but I thought I'd ask again about a free 'Code Snippets" add-in for VB.Net 2003. Any help will be very much appreciated. Thank you, Don
1
by: David C. Barber | last post by:
Asking again, I've just built my first Setup-Installable VB 2005 package. I have the full Profession Edition VS 2005, not the Express edition, and am patched to the current SP. It installs on...
1
by: little | last post by:
hi! i had actually joined a contest which puzzled me a lot. in return, i want to figure it out. i tried a lot of options and coding stuff but none of them worked. so, i decided to come to an...
22
patjones
by: patjones | last post by:
Hi - I have a bound form with a bunch of text boxes connected to various fields. When someone types a search value into txtSearch and either tabs out or hits Enter, the following code runs...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.