why will this not work in C#

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZQ==?=, Nov 10, 2004.

  1. 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.cursor='hand'");
    e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + " DataGrid1:"
    + "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");

    }
    }
    =?Utf-8?B?TWlrZQ==?=, Nov 10, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?TWlrZQ==?=

    Hans Kesting Guest

    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.cursor='hand'");
    > e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + "
    > 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
    Hans Kesting, Nov 10, 2004
    #2
    1. Advertising

  3. 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.cursor='hand'");
    > > e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + "
    > > 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
    >
    >
    >
    =?Utf-8?B?TWlrZQ==?=, Nov 10, 2004
    #3
  4. =?Utf-8?B?TWlrZQ==?=

    Hans Kesting Guest

    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.cursor='hand'");
    >>> e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + "
    >>> 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
    Hans Kesting, Nov 10, 2004
    #4
  5. 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.cursor='hand'");
    > >>> e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + "
    > >>> 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

    >
    >
    >
    =?Utf-8?B?TWlrZQ==?=, Nov 10, 2004
    #5
  6. =?Utf-8?B?TWlrZQ==?=

    Hans Kesting Guest

    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.cursor='hand'");
    >>>>> e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + "
    >>>>> 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
    Hans Kesting, Nov 10, 2004
    #6
  7. 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.cursor='hand'");
    > >>>>> e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + "
    > >>>>> 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

    >
    >
    >
    =?Utf-8?B?TWlrZQ==?=, Nov 10, 2004
    #7
  8. =?Utf-8?B?TWlrZQ==?=

    sinaja

    Joined:
    Mar 6, 2009
    Messages:
    1
    Attribute.Add syntax

    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: Mar 6, 2009
    sinaja, Mar 6, 2009
    #8
  9. =?Utf-8?B?TWlrZQ==?=

    ezekiel571

    Joined:
    Apr 22, 2011
    Messages:
    1
    You're missing the single quotes...

    ezekiel571, Apr 22, 2011
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Francis Ardi
    Replies:
    3
    Views:
    425
    Sudsy
    Jul 10, 2003
  2. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    443
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    853
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,739
    Smokey Grindel
    Dec 2, 2006
  5. Skybuck Flying
    Replies:
    16
    Views:
    651
    tragomaskhalos
    Aug 25, 2007
Loading...

Share This Page