link on an entire row in a datagrid

Discussion in 'ASP .Net Web Controls' started by ThunderMusic, Jan 3, 2006.

  1. ThunderMusic

    ThunderMusic Guest

    Hi,
    In my page, I have a datagrid. I want a link to be "bound" to the entire
    row. How can I do that? I have my datagrid, my colums and all, but how do I
    add the link so when I click on anything in the row, it does something
    (OnClick="MySomething")? Will I have to add the "OnClick" event to all my
    rows?

    Thanks

    ThunderMusic
    ThunderMusic, Jan 3, 2006
    #1
    1. Advertising

  2. ThunderMusic

    ThunderMusic Guest

    ok, never mind, I just found someone already did it.

    sorry

    "ThunderMusic" <> wrote in message
    news:uXM%...
    > Hi,
    > In my page, I have a datagrid. I want a link to be "bound" to the entire
    > row. How can I do that? I have my datagrid, my colums and all, but how do
    > I add the link so when I click on anything in the row, it does something
    > (OnClick="MySomething")? Will I have to add the "OnClick" event to all my
    > rows?
    >
    > Thanks
    >
    > ThunderMusic
    >
    ThunderMusic, Jan 3, 2006
    #2
    1. Advertising

  3. Got a link?
    Keith Patrick, Jan 3, 2006
    #3
  4. ThunderMusic

    ThunderMusic Guest

    no, because it was in our code... Someone did it within our team...

    we add a OnClick event on the created Item within the ItemCreated event of
    the DataGrid like this:

    e.Item.Attributes.Add("OnClick", "javascript:poP(" + e.Item.Cells[0].Text +
    ");");

    I hope it helps

    ThunderMusic

    "Keith Patrick" <> wrote in message
    news:...
    > Got a link?
    >
    ThunderMusic, Jan 3, 2006
    #4
  5. Cool, yeah, it's been something I've been wanting to put on a user screen
    for over a year now but never sat down to try out any way to get it working,
    but I'm at a point where I can redo the screen, so it's back on my tasklist.
    Thanks!
    Keith Patrick, Jan 4, 2006
    #5
  6. BTW: I've found it's better to do this OnItemDataBound, as any templated
    controls in there don't get a NamingContainer-qualified ClientID until the
    binding has occured. This example has a radio button called "Selected" in
    the first column:
    if ( e.Item.ItemType != ListItemType.Item
    && e.Item.ItemType != ListItemType.AlternatingItem)
    {
    return;
    }

    e.Item.Attributes["onClick"] =
    "javascript:document.getElementById('" +
    e.Item.Cells[0].FindControl("Selected").ClientID + "').Selected = true;";



    At ItemCreated, the ClientID is "Selected", wherease on DataBound, it's
    "ctrl00_OwningDataGrid_Selected."
    Keith Patrick, Jan 9, 2006
    #6
    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. Peter
    Replies:
    0
    Views:
    473
    Peter
    Sep 9, 2004
  2. Edward

    Select Entire datagrid Row when down & up key is pressed

    Edward, May 19, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    124
    Edward
    May 19, 2004
  3. D
    Replies:
    0
    Views:
    197
  4. Sehboo

    Datagrid - select entire row

    Sehboo, Aug 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    252
    Teemu Keiski
    Apr 17, 2006
  5. Replies:
    7
    Views:
    102
    James Edward Gray II
    Jul 4, 2005
Loading...

Share This Page