Clickevent in datacell

Discussion in 'ASP .Net Datagrid Control' started by MA, Aug 16, 2004.

  1. MA

    MA Guest

    Hi all!

    I have a datagrid that i fill up from a database.

    I create it with help of datatable and datarow. Then I creates a new
    dataview and binds it to the datatable.

    How do I get the clickevent on each cell with this?

    I want to click on a cell in my grid, get the cellID or some else info that
    can identify the cell. After that I want to go to a function in my code
    behinde and launch a new window with extended information.

    Can anyone tell me how to do this or give me a url with info?

    /Marre
     
    MA, Aug 16, 2004
    #1
    1. Advertising

  2. In ItemDataBound event add Attributes["onclick"] to every cell of data
    items. Pass cell id to the event handler javascript function.

    Example:

    private void myGrid_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    ListItemType itemType = e.Item.ItemType;
    if ((itemType == ListItemType.Pager) ||
    (itemType == ListItemType.Header) ||
    (itemType == ListItemType.Footer))
    {
    return;
    }

    for (int i=0; i<e.Item.Cells.Count; i++)
    e.Item.Cells.Attributes["onclick"]=String.Format
    ("'onclickHandler(this,{0})'", i);
    }

    Eliyahu

    "MA" <> wrote in message
    news:...
    > Hi all!
    >
    > I have a datagrid that i fill up from a database.
    >
    > I create it with help of datatable and datarow. Then I creates a new
    > dataview and binds it to the datatable.
    >
    > How do I get the clickevent on each cell with this?
    >
    > I want to click on a cell in my grid, get the cellID or some else info

    that
    > can identify the cell. After that I want to go to a function in my code
    > behinde and launch a new window with extended information.
    >
    > Can anyone tell me how to do this or give me a url with info?
    >
    > /Marre
    >
    >
     
    Eliyahu Goldin, Aug 17, 2004
    #2
    1. Advertising

  3. MA

    MA Guest

    Yeah! This works if I remove the ' around the functionname.

    Thanx Eliyahu!!
    /Marre

    "Eliyahu Goldin" <> wrote in message
    news:%...
    > In ItemDataBound event add Attributes["onclick"] to every cell of data
    > items. Pass cell id to the event handler javascript function.
    >
    > Example:
    >
    > private void myGrid_ItemDataBound(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > {
    > ListItemType itemType = e.Item.ItemType;
    > if ((itemType == ListItemType.Pager) ||
    > (itemType == ListItemType.Header) ||
    > (itemType == ListItemType.Footer))
    > {
    > return;
    > }
    >
    > for (int i=0; i<e.Item.Cells.Count; i++)
    > e.Item.Cells.Attributes["onclick"]=String.Format
    > ("'onclickHandler(this,{0})'", i);
    > }
    >
    > Eliyahu
    >
    > "MA" <> wrote in message
    > news:...
    > > Hi all!
    > >
    > > I have a datagrid that i fill up from a database.
    > >
    > > I create it with help of datatable and datarow. Then I creates a new
    > > dataview and binds it to the datatable.
    > >
    > > How do I get the clickevent on each cell with this?
    > >
    > > I want to click on a cell in my grid, get the cellID or some else info

    > that
    > > can identify the cell. After that I want to go to a function in my code
    > > behinde and launch a new window with extended information.
    > >
    > > Can anyone tell me how to do this or give me a url with info?
    > >
    > > /Marre
    > >
    > >

    >
    >
     
    MA, Aug 18, 2004
    #3
    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. Jayender
    Replies:
    1
    Views:
    956
    Jayender
    Aug 9, 2006
  2. Kodara
    Replies:
    0
    Views:
    772
    Kodara
    Jul 16, 2008
  3. Jeff
    Replies:
    1
    Views:
    407
    Nathan Sokalski
    Oct 8, 2008
  4. Helmut

    Problem with ClickEvent

    Helmut, Aug 25, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    138
    Tonix
    Aug 26, 2004
Loading...

Share This Page