why will this not work in C#

Discussion in 'ASP .Net' started by Guest, Nov 10, 2004.

  1. Guest

    Guest Guest

    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','')");

    }
    }
     
    Guest, Nov 10, 2004
    #1
    1. Advertisements

  2. Guest

    Hans Kesting Guest

    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. Advertisements

  3. Guest

    Guest Guest

    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.
     
    Guest, Nov 10, 2004
    #3
  4. Guest

    Hans Kesting Guest

    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, Nov 10, 2004
    #4
  5. Guest

    Guest Guest

    yes its in the code and yes I added the || (which made no difference)
     
    Guest, Nov 10, 2004
    #5
  6. Guest

    Hans Kesting Guest

    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, Nov 10, 2004
    #6
  7. Guest

    Guest Guest

    I got it working thx

     
    Guest, Nov 10, 2004
    #7
  8. Guest

    sinaja

    Joined:
    Mar 6, 2009
    Messages:
    1
    Likes Received:
    0
    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. Guest

    ezekiel571

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

     
    ezekiel571, Apr 22, 2011
    #9
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.