ok,asking for C# help again

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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 ==
 
Use "is"

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

Note there are no quotes around the type.
 
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")))
 
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
 
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
 
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... :-)
 
Back
Top