Which cell was clicked

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Which cell was clicked

    I would like to create a postBack when user click on the cell:

    In my dataGrid, I put the button column:
    <asp:buttoncolumn visible="false" commandname="Select"></asp:buttoncolumn>

    Then on ItemDataBound, I add :

    Private Sub dgdMedia_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    dgdMedia.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(2).Controls(0),
    LinkButton)
    e.Item.Attributes("onClick") =
    Page.GetPostBackClientHyperlink(button, "myArgument")
    e.Item.Attributes.Add("onMouseOver",
    "javascript:this.style.cursor='pointer';")
    e.Item.Attributes.Add("omMouseOut",
    "javascript:this.style.cursor='normal';")
    End If
    End Sub

    And finally:

    Private Sub dgdMedia_ItemCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
    dgdMedia.ItemCommand

    Dim button As LinkButton = CType(e.Item.Cells(2).Controls(0),
    LinkButton)

    Response.Write(button.CommandArgument)
    Response.Write(e.Item.ItemIndex())'i get this one and it tells me
    the clicked row
    End Sub

    How can I get the indeks of a cell, which was clicked?
    Why the argument of a button is empty? It should be "myArgument"

    Thank you for yur answer,
    Simon


    simon Guest

  2. Similar Questions and Discussions

    1. How to set cell background based on cell value when datagrid is displayed
      I would like to check a datagrid cell value, and change the color of the cell background, when a datagrid is displayed. I want to do this as early...
    2. e.Item.Cells[] doesn't get the content of the cell i clicked in(sorry this is the full message.
      e.item.cells only gets you to the cell, you then need to access the control in the cell and look at the control's text, not the cell's text. It...
    3. I need to have a tooltip appear over a cell showing data from another cell in the same row.
      I have a datagrid with locations from around the world. In hidden cells, I have the Lat and Long of that location. I need to be able to mouseover...
    4. How to determine which cell was clicked in as ASP.NET DataGrid
      Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
    5. RadioButtonList In A DataGrid Cell - Can I find the selected button without editing the cell?
      I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a...
  3. #2

    Default Re: Which cell was clicked

    unless u write client-side code to pass id of cell clicked.. its not
    possible.

    or either.. u shud have a button on each cell.. and if that cells button is
    clicked.. u can handle its click event.

    otherwise.. .net code is server-side.. and no points of click is passed to
    server. .. except for image buttons.

    on image buttons alone.. if u click on image.. the position (x,y) of click
    is passed back to click event of image button

    'Harish.

    "simon" <simon.zupan@stud-moderna.si> wrote in message
    news:%2377DFO4JEHA.2624@TK2MSFTNGP09.phx.gbl...
    > I would like to create a postBack when user click on the cell:
    >
    > In my dataGrid, I put the button column:
    > <asp:buttoncolumn visible="false" commandname="Select"></asp:buttoncolumn>
    >
    > Then on ItemDataBound, I add :
    >
    > Private Sub dgdMedia_ItemDataBound(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    > dgdMedia.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(2).Controls(0),
    > LinkButton)
    > e.Item.Attributes("onClick") =
    > Page.GetPostBackClientHyperlink(button, "myArgument")
    > e.Item.Attributes.Add("onMouseOver",
    > "javascript:this.style.cursor='pointer';")
    > e.Item.Attributes.Add("omMouseOut",
    > "javascript:this.style.cursor='normal';")
    > End If
    > End Sub
    >
    > And finally:
    >
    > Private Sub dgdMedia_ItemCommand(ByVal source As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
    > dgdMedia.ItemCommand
    >
    > Dim button As LinkButton = CType(e.Item.Cells(2).Controls(0),
    > LinkButton)
    >
    > Response.Write(button.CommandArgument)
    > Response.Write(e.Item.ItemIndex())'i get this one and it tells me
    > the clicked row
    > End Sub
    >
    > How can I get the indeks of a cell, which was clicked?
    > Why the argument of a button is empty? It should be "myArgument"
    >
    > Thank you for yur answer,
    > Simon
    >
    >

    Harish Palaniappan Guest

Posting Permissions

  • You may not post new threads
  • You may 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