Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > why will this not work in C#

Reply
Thread Tools

why will this not work in C#

 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      11-10-2004
What i'm trying to do is allow the user click on a row in the datagrid and it
highlights the row. I have the select button for my grid and its hidden.
I can do this in VB.NET successfully with this same code but when i put it
in C# it does not work.

what am i missing?

private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.SelectedItem)
{
e.Item.Attributes.Add("onmouseover",
"this.style.bacgroundcolor='#FFFFFF';this.style.cu rsor='hand'");
e.Item.Attributes.Add("onclick","javascript:__doPo stBack('" + " DataGrid1:"
+ "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");

}
}
 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      11-10-2004
Mike wrote:
> What i'm trying to do is allow the user click on a row in the
> datagrid and it highlights the row. I have the select button for my
> grid and its hidden.
> I can do this in VB.NET successfully with this same code but when i
> put it in C# it does not work.
>
> what am i missing?
>
> private void DataGrid1_ItemCreated(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
> ListItemType.AlternatingItem | e.Item.ItemType ==
> ListItemType.SelectedItem) {
> e.Item.Attributes.Add("onmouseover",
> "this.style.bacgroundcolor='#FFFFFF';this.style.cu rsor='hand'");
> e.Item.Attributes.Add("onclick","javascript:__doPo stBack('" + "
> DataGrid1:" + "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");
>
> }
> }


What exactly do you mean by "does not work"?

One thing I notice: you use "|", which is C# for "bitwise OR"
(with integer oparands).
I think you want "||" (C# for "boolean OR") (with boolean operands)

Hans Kesting


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      11-10-2004
It doesn't work. It does not allow me to click on a row and highlight the
row, like it does in the VB.NET world.


"Hans Kesting" wrote:

> Mike wrote:
> > What i'm trying to do is allow the user click on a row in the
> > datagrid and it highlights the row. I have the select button for my
> > grid and its hidden.
> > I can do this in VB.NET successfully with this same code but when i
> > put it in C# it does not work.
> >
> > what am i missing?
> >
> > private void DataGrid1_ItemCreated(object sender,
> > System.Web.UI.WebControls.DataGridItemEventArgs e)
> > {
> > if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
> > ListItemType.AlternatingItem | e.Item.ItemType ==
> > ListItemType.SelectedItem) {
> > e.Item.Attributes.Add("onmouseover",
> > "this.style.bacgroundcolor='#FFFFFF';this.style.cu rsor='hand'");
> > e.Item.Attributes.Add("onclick","javascript:__doPo stBack('" + "
> > DataGrid1:" + "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");
> >
> > }
> > }

>
> What exactly do you mean by "does not work"?
>
> One thing I notice: you use "|", which is C# for "bitwise OR"
> (with integer oparands).
> I think you want "||" (C# for "boolean OR") (with boolean operands)
>
> Hans Kesting
>
>
>

 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      11-10-2004
Mike wrote:
> It doesn't work. It does not allow me to click on a row and highlight
> the row, like it does in the VB.NET world.
>


Is the mouseover code added (see html-source in the browser)? (probably not)

Did you change | to || (double-pipe) in your code?

Hans Kesting

>
> "Hans Kesting" wrote:
>
>> Mike wrote:
>>> What i'm trying to do is allow the user click on a row in the
>>> datagrid and it highlights the row. I have the select button for my
>>> grid and its hidden.
>>> I can do this in VB.NET successfully with this same code but when i
>>> put it in C# it does not work.
>>>
>>> what am i missing?
>>>
>>> private void DataGrid1_ItemCreated(object sender,
>>> System.Web.UI.WebControls.DataGridItemEventArgs e)
>>> {
>>> if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
>>> ListItemType.AlternatingItem | e.Item.ItemType ==
>>> ListItemType.SelectedItem) {
>>> e.Item.Attributes.Add("onmouseover",
>>> "this.style.bacgroundcolor='#FFFFFF';this.style.cu rsor='hand'");
>>> e.Item.Attributes.Add("onclick","javascript:__doPo stBack('" + "
>>> DataGrid1:" + "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");
>>>
>>> }
>>> }

>>
>> What exactly do you mean by "does not work"?
>>
>> One thing I notice: you use "|", which is C# for "bitwise OR"
>> (with integer oparands).
>> I think you want "||" (C# for "boolean OR") (with boolean operands)
>>
>> Hans Kesting



 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      11-10-2004
yes its in the code and yes I added the || (which made no difference)


"Hans Kesting" wrote:

> Mike wrote:
> > It doesn't work. It does not allow me to click on a row and highlight
> > the row, like it does in the VB.NET world.
> >

>
> Is the mouseover code added (see html-source in the browser)? (probably not)
>
> Did you change | to || (double-pipe) in your code?
>
> Hans Kesting
>
> >
> > "Hans Kesting" wrote:
> >
> >> Mike wrote:
> >>> What i'm trying to do is allow the user click on a row in the
> >>> datagrid and it highlights the row. I have the select button for my
> >>> grid and its hidden.
> >>> I can do this in VB.NET successfully with this same code but when i
> >>> put it in C# it does not work.
> >>>
> >>> what am i missing?
> >>>
> >>> private void DataGrid1_ItemCreated(object sender,
> >>> System.Web.UI.WebControls.DataGridItemEventArgs e)
> >>> {
> >>> if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
> >>> ListItemType.AlternatingItem | e.Item.ItemType ==
> >>> ListItemType.SelectedItem) {
> >>> e.Item.Attributes.Add("onmouseover",
> >>> "this.style.bacgroundcolor='#FFFFFF';this.style.cu rsor='hand'");
> >>> e.Item.Attributes.Add("onclick","javascript:__doPo stBack('" + "
> >>> DataGrid1:" + "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");
> >>>
> >>> }
> >>> }
> >>
> >> What exactly do you mean by "does not work"?
> >>
> >> One thing I notice: you use "|", which is C# for "bitwise OR"
> >> (with integer oparands).
> >> I think you want "||" (C# for "boolean OR") (with boolean operands)
> >>
> >> Hans Kesting

>
>
>

 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      11-10-2004
Mike wrote:
> yes its in the code and yes I added the || (which made no difference)
>
>


Then I don't know, apart from something I noticed just now:
you write "bacgroundcolor" in your post, which should be "backgroundcolor"
(but this is probably just a typo in your post)

Hans Kesting


> "Hans Kesting" wrote:
>
>> Mike wrote:
>>> It doesn't work. It does not allow me to click on a row and
>>> highlight the row, like it does in the VB.NET world.
>>>

>>
>> Is the mouseover code added (see html-source in the browser)?
>> (probably not)
>>
>> Did you change | to || (double-pipe) in your code?
>>
>> Hans Kesting
>>
>>>
>>> "Hans Kesting" wrote:
>>>
>>>> Mike wrote:
>>>>> What i'm trying to do is allow the user click on a row in the
>>>>> datagrid and it highlights the row. I have the select button for
>>>>> my grid and its hidden.
>>>>> I can do this in VB.NET successfully with this same code but when
>>>>> i put it in C# it does not work.
>>>>>
>>>>> what am i missing?
>>>>>
>>>>> private void DataGrid1_ItemCreated(object sender,
>>>>> System.Web.UI.WebControls.DataGridItemEventArgs e)
>>>>> {
>>>>> if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
>>>>> ListItemType.AlternatingItem | e.Item.ItemType ==
>>>>> ListItemType.SelectedItem) {
>>>>> e.Item.Attributes.Add("onmouseover",
>>>>> "this.style.bacgroundcolor='#FFFFFF';this.style.cu rsor='hand'");
>>>>> e.Item.Attributes.Add("onclick","javascript:__doPo stBack('" + "
>>>>> DataGrid1:" + "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");
>>>>>
>>>>> }
>>>>> }
>>>>
>>>> What exactly do you mean by "does not work"?
>>>>
>>>> One thing I notice: you use "|", which is C# for "bitwise OR"
>>>> (with integer oparands).
>>>> I think you want "||" (C# for "boolean OR") (with boolean operands)
>>>>
>>>> Hans Kesting



 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      11-10-2004
I got it working thx

"Hans Kesting" wrote:

> Mike wrote:
> > yes its in the code and yes I added the || (which made no difference)
> >
> >

>
> Then I don't know, apart from something I noticed just now:
> you write "bacgroundcolor" in your post, which should be "backgroundcolor"
> (but this is probably just a typo in your post)
>
> Hans Kesting
>
>
> > "Hans Kesting" wrote:
> >
> >> Mike wrote:
> >>> It doesn't work. It does not allow me to click on a row and
> >>> highlight the row, like it does in the VB.NET world.
> >>>
> >>
> >> Is the mouseover code added (see html-source in the browser)?
> >> (probably not)
> >>
> >> Did you change | to || (double-pipe) in your code?
> >>
> >> Hans Kesting
> >>
> >>>
> >>> "Hans Kesting" wrote:
> >>>
> >>>> Mike wrote:
> >>>>> What i'm trying to do is allow the user click on a row in the
> >>>>> datagrid and it highlights the row. I have the select button for
> >>>>> my grid and its hidden.
> >>>>> I can do this in VB.NET successfully with this same code but when
> >>>>> i put it in C# it does not work.
> >>>>>
> >>>>> what am i missing?
> >>>>>
> >>>>> private void DataGrid1_ItemCreated(object sender,
> >>>>> System.Web.UI.WebControls.DataGridItemEventArgs e)
> >>>>> {
> >>>>> if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
> >>>>> ListItemType.AlternatingItem | e.Item.ItemType ==
> >>>>> ListItemType.SelectedItem) {
> >>>>> e.Item.Attributes.Add("onmouseover",
> >>>>> "this.style.bacgroundcolor='#FFFFFF';this.style.cu rsor='hand'");
> >>>>> e.Item.Attributes.Add("onclick","javascript:__doPo stBack('" + "
> >>>>> DataGrid1:" + "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");
> >>>>>
> >>>>> }
> >>>>> }
> >>>>
> >>>> What exactly do you mean by "does not work"?
> >>>>
> >>>> One thing I notice: you use "|", which is C# for "bitwise OR"
> >>>> (with integer oparands).
> >>>> I think you want "||" (C# for "boolean OR") (with boolean operands)
> >>>>
> >>>> Hans Kesting

>
>
>

 
Reply With Quote
 
sinaja sinaja is offline
Junior Member
Join Date: Mar 2009
Posts: 1
 
      03-06-2009
Hi, I am new to C# so this may be an easy one to spot ...
Why does this line of code work :

imgctrl.Attributes.Add("onmouseout", "this.src='products/images/zenzai_off.gif'");

but the following does not (the image does not change)

string imageOnUrl = "products/images/zenzai_on.gif";
imgctrl.Attributes.Add("onmouseover", "this.src= imageOnUrl");

Kind regards
 

Last edited by sinaja; 03-06-2009 at 09:47 AM..
Reply With Quote
 
ezekiel571 ezekiel571 is offline
Junior Member
Join Date: Apr 2011
Posts: 1
 
      04-21-2011
You're missing the single quotes...

Quote:
Originally Posted by sinaja View Post
Hi, I am new to C# so this may be an easy one to spot ...
Why does this line of code work :

imgctrl.Attributes.Add("onmouseout", "this.src='products/images/zenzai_off.gif'");

but the following does not (the image does not change)

string imageOnUrl = "products/images/zenzai_on.gif";
imgctrl.Attributes.Add("onmouseover", "this.src= imageOnUrl");

Kind regards
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why :: ? Why not : ? Why not . ? <- less clutter ?!? Skybuck Flying C++ 16 08-25-2007 09:48 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM
Point and Click Weather Forecasts does not work on all browsers. Why not? Francis Ardi Java 3 07-10-2003 05:26 PM



Advertisments