ASP.NET 1.1 DataGrid Question

Discussion in 'ASP .Net' started by =?Utf-8?B?SG9seXNtb2tl?=, Jul 25, 2006.

  1. Hello,

    I have a datagrid with linkbutton on the first column which shows a number
    Id to select a particular record. Currently the users have to click on the
    number (column1) to select. Instead, I want to change this behaviour to
    rowclick. I mean the users can click on any columns of that row to select a
    particular record.

    Remember I got to use LinkButton on the first column always.

    TIA,
    Holy
    =?Utf-8?B?SG9seXNtb2tl?=, Jul 25, 2006
    #1
    1. Advertising

  2. Handle ItemDataBound event like this:

    ' Visual Basic
    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
    Handles DataGrid1.ItemDataBound
    Dim itemType As ListItemType = e.Item.ItemType
    If ((itemType = ListItemType.Pager) Or _
    (itemType = ListItemType.Header) Or _
    (itemType = ListItemType.Footer)) Then
    Return
    Else
    Dim button As LinkButton = _
    CType(e.Item.Cells(0).Controls(0), LinkButton)
    e.Item.Attributes("onclick") = _
    Page.GetPostBackClientHyperlink(button, "")
    End If
    End Sub

    // C#
    private void DataGrid1_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"] =
    Page.GetPostBackClientHyperlink(button, "");



    }

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]

    "Holysmoke" <> wrote in message
    news:...
    > Hello,
    >
    > I have a datagrid with linkbutton on the first column which shows a number
    > Id to select a particular record. Currently the users have to click on the
    > number (column1) to select. Instead, I want to change this behaviour to
    > rowclick. I mean the users can click on any columns of that row to select
    > a
    > particular record.
    >
    > Remember I got to use LinkButton on the first column always.
    >
    > TIA,
    > Holy
    >
    Eliyahu Goldin, Jul 25, 2006
    #2
    1. Advertising

  3. Thank you. It works fine.

    "Eliyahu Goldin" wrote:

    > Handle ItemDataBound event like this:
    >
    > ' Visual Basic
    > Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
    > ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
    > Handles DataGrid1.ItemDataBound
    > Dim itemType As ListItemType = e.Item.ItemType
    > If ((itemType = ListItemType.Pager) Or _
    > (itemType = ListItemType.Header) Or _
    > (itemType = ListItemType.Footer)) Then
    > Return
    > Else
    > Dim button As LinkButton = _
    > CType(e.Item.Cells(0).Controls(0), LinkButton)
    > e.Item.Attributes("onclick") = _
    > Page.GetPostBackClientHyperlink(button, "")
    > End If
    > End Sub
    >
    > // C#
    > private void DataGrid1_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"] =
    > Page.GetPostBackClientHyperlink(button, "");
    >
    >
    >
    > }
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    > "Holysmoke" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I have a datagrid with linkbutton on the first column which shows a number
    > > Id to select a particular record. Currently the users have to click on the
    > > number (column1) to select. Instead, I want to change this behaviour to
    > > rowclick. I mean the users can click on any columns of that row to select
    > > a
    > > particular record.
    > >
    > > Remember I got to use LinkButton on the first column always.
    > >
    > > TIA,
    > > Holy
    > >

    >
    >
    >
    =?Utf-8?B?SG9seXNtb2tl?=, Jul 26, 2006
    #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. DC
    Replies:
    3
    Views:
    2,420
  2. Bit Byte
    Replies:
    1
    Views:
    838
    Teemu Keiski
    Jan 28, 2007
  3. Andreas Klemt
    Replies:
    0
    Views:
    296
    Andreas Klemt
    Oct 8, 2003
  4. roberto
    Replies:
    1
    Views:
    223
    roberto
    Feb 17, 2005
  5. Phani
    Replies:
    2
    Views:
    124
    Phani
    Apr 25, 2005
Loading...

Share This Page