ok,asking for C# help again

G

Guest

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
 
M

Mark Rae [MVP]

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 ==
 
A

Aidy

Use "is"

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

Note there are no quotes around the type.
 
M

Mark Fitzpatrick

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")))
 
M

mark4asp

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

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
 
G

Guest

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
 
M

Mark Rae [MVP]

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... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top