Professional Web Applications Themes

Selecting row in datagrid by clicking everyway on the item - ASP.NET Data Grid Control

I would select rows in datagrid by clicking on the desired row. Someone csn tell me how i can do that? Thanks....

Sponsored Links
  1. #1

    Default Selecting row in datagrid by clicking everyway on the item

    I would select rows in datagrid by clicking on the desired row.
    Someone csn tell me how i can do that?
    Thanks.
    Sponsored Links
    Liuc Guest

  2. #2

    Default RE: Selecting row in datagrid by clicking everyway on the item

    Hi,

    This is addressed in this article:

    Top Questions about the DataGrid Web Server Control
    [url]http://msdn.microsoft.com/library/en-us/dv_vstechart/html/vbtchTopQuestionsA[/url]
    boutASPNETDataGridServerControl.asp

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    [url]http://www.microsoft.com/protect[/url] site and perform the three straightforward
    steps listed to improve your computerís security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: [email]liucemail.it[/email] (Liuc)
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > Subject: Selecting row in datagrid by clicking everyway on the item
    > Date: 12 Nov 2003 05:41:03 -0800
    > Organization: [url]http://groups.google.com[/url]
    > Lines: 3
    > Message-ID: <8a893c92.0311120541.4abf6350posting.google.com >
    > NNTP-Posting-Host: 193.204.78.225
    > Content-Type: text/plain; cht=ISO-8859-1
    > Content-Transfer-Encoding: 8bit
    > X-Trace: posting.google.com 1068644463 2886 127.0.0.1 (12 Nov 2003
    13:41:03 GMT)
    > X-Complaints-To: [email]groups-abusegoogle.com[/email]
    > NNTP-Posting-Date: Wed, 12 Nov 2003 13:41:03 +0000 (UTC)
    > Path:
    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
    e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!postnew s1.google.com!no
    t-for-mail
    > Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol:7415
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    >
    > I would select rows in datagrid by clicking on the desired row.
    > Someone csn tell me how i can do that?
    > Thanks.
    >
    Mike Moore [MSFT] Guest

  3. #3

    Default Re: Selecting row in datagrid by clicking everyway on the item

    Thak you for the answer, but i can't find the article.
    Liuc Guest

  4. #4

    Default Re: Selecting row in datagrid by clicking everyway on the item

    Hi,

    I copied the link from my previous post, removed the carriage return, and
    pasted the result into a browser and it did get the article.

    In any case, here is the text from the click anywhere section of the
    article.

    Selecting Rows by Clicking Anywhere
    The default model for selecting rows in the grid is for you to add a Select
    button (actually, a LinkButton control) whose CommandName property is set
    to "Select." When the button is clicked, the DataGrid control receives the
    Select command and automatically displays the row in selected mode.

    Not everyone likes having an explicit Select button, and a common question
    is how to implement the feature where users can click anywhere in a grid
    row to select it. The solution is to perform a kind of sleight-of-hand in
    the grid. You add the Select LinkButton control as normal. Users can still
    use it, or you can hide it. In either event, you then inject some client
    script into the page that effectively duplicates the functionality of the
    Select button for the row as a whole.

    The example below shows how. In the grid's ItemDataBound handler, first
    make sure that you are not in the header, footer, or pager. Then get a
    reference to the Select button, which in this instance is assumed to be the
    first control in the first cell. You then call a little-known method called
    GetPostBackClientHyperlink. This method returns the name of the postback
    call for the designated control. In other words, if you pass in a reference
    to a LinkButton control, it returns the name of the client function call
    that will perform the postback.

    Finally, you assign the client-side method to the item itself. When the
    grid renders, it renders as an HTML table. By assigning the method to the
    item, it is the equivalent of adding client-side code to each row (<TR>
    element) in the table. The grid's Item object does not directly support a
    way to assign client code to it, but you can do that by using its
    Attributes collection, which passes anything you assign to it through to
    the browser.

    Note One small disadvantage of this technique is that it adds somewhat to
    the stream rendered to the browser, and it adds information for each row to
    view state.
    ' 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, "");
    }


    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    [url]http://www.microsoft.com/protect[/url] site and perform the three straightforward
    steps listed to improve your computerís security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: [email]liucemail.it[/email] (Liuc)
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    > Subject: Re: Selecting row in datagrid by clicking everyway on the item
    > Date: 13 Nov 2003 00:13:14 -0800
    > Organization: [url]http://groups.google.com[/url]
    > Lines: 1
    > Message-ID: <8a893c92.0311130013.5e9cee63posting.google.com >
    > References: <8a893c92.0311120541.4abf6350posting.google.com >
    <kBuiHfWqDHA.1804cpmsftngxa06.phx.gbl>
    > NNTP-Posting-Host: 193.204.78.252
    > Content-Type: text/plain; cht=ISO-8859-1
    > Content-Transfer-Encoding: 8bit
    > X-Trace: posting.google.com 1068711194 15250 127.0.0.1 (13 Nov 2003
    08:13:14 GMT)
    > X-Complaints-To: [email]groups-abusegoogle.com[/email]
    > NNTP-Posting-Date: Thu, 13 Nov 2003 08:13:14 +0000 (UTC)
    > Path:
    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
    e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!postnew s1.google.com!no
    t-for-mail
    > Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol:7428
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    >
    > Thak you for the answer, but i can't find the article.
    >
    Mike Moore [MSFT] Guest

  5. #5

    Default Re: Selecting row in datagrid by clicking everyway on the item

    Great! Thank you!
    Liuc Guest

Similar Threads

  1. Selecting Item(s) on a DataGrid
    By Jaz Chana in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: May 9th, 07:51 PM
  2. Selecting related data in multiple DataGrids when clicking a row
    By prichards14 in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: December 17th, 02:29 PM
  3. Replies: 2
    Last Post: February 5th, 12:11 AM
  4. Replies: 6
    Last Post: January 17th, 07:46 PM
  5. Replies: 1
    Last Post: September 22nd, 04:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139