Click anywhere in a row....

Discussion in 'ASP .Net Datagrid Control' started by UJ, May 12, 2005.

  1. UJ

    UJ Guest

    Is there any way to tell when a user clicks anywhere in a row? The only way
    I can think to do it is to make each column a link with a button and use the
    text as the value I want displayed.

    TIA.
     
    UJ, May 12, 2005
    #1
    1. Advertising

  2. UJ

    Sambathraj Guest

    Hi,
    Try usng Onclick event for the TR
    Regards
    Sambath
    "UJ" <> wrote in message
    news:...
    > Is there any way to tell when a user clicks anywhere in a row? The only
    > way I can think to do it is to make each column a link with a button and
    > use the text as the value I want displayed.
    >
    > TIA.
    >
    >
     
    Sambathraj, May 12, 2005
    #2
    1. Advertising

  3. There is a number of ways. The easiest one (C# syntax):

    Add a hidden button column:

    <asp:datagrid id=myGrid runat="server" AutoGenerateColumns="False"
    OnItemDataBound="myGrid_ItemDataBound" >
    <Columns>
    <asp:ButtonColumn ButtonType="LinkButton" CommandName="Select"
    Visible="False"></asp:ButtonColumn>
    <asp:BoundColumn DataField="user_nm" HeaderText="Logon
    Name"></asp:BoundColumn>
    <asp:BoundColumn DataField="last_nm" HeaderText="Last
    Name"></asp:BoundColumn>
    <asp:BoundColumn DataField="first_nm" HeaderText="First
    Name"></asp:BoundColumn>
    </Columns>
    </asp:datagrid>

    and setup an ItemDataBound event handler:

    protected 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;
    }
    LinkButton button = (LinkButton) e.Item.Cells[0].Controls[0];
    e.Item.Attributes["onclick"] = this.GetPostBackClientHyperlink
    (button, "");
    }

    Eliyahu

    "UJ" <> wrote in message
    news:...
    > Is there any way to tell when a user clicks anywhere in a row? The only

    way
    > I can think to do it is to make each column a link with a button and use

    the
    > text as the value I want displayed.
    >
    > TIA.
    >
    >
     
    Eliyahu Goldin, May 12, 2005
    #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. Fernando Lopes
    Replies:
    0
    Views:
    3,196
    Fernando Lopes
    Apr 28, 2005
  2. .NETn00b
    Replies:
    1
    Views:
    984
    Eliyahu Goldin
    Nov 28, 2005
  3. misiek
    Replies:
    0
    Views:
    2,285
    misiek
    Feb 20, 2006
  4. =?Utf-8?B?SmF5?=
    Replies:
    0
    Views:
    614
    =?Utf-8?B?SmF5?=
    Jun 2, 2006
  5. Hardy Wang
    Replies:
    2
    Views:
    7,986
    Hardy Wang
    Sep 15, 2006
Loading...

Share This Page