vendredi 29 mai 2015

jquery function for getting div inside row Table

I have a Datalist with three columns or fields: Column1: Some data Column2: Linkbutton Update Column3: div "divCheck", by default it's hide.

<asp:DataList ID="MyDataList" runat="server" EnableViewState="True">
      <HeaderTemplate>
      </HeaderTemplate>
      <ItemTemplate>
          <table width="100%">
              <tr id="ItemRow" runat="server">
                  <td >
                      <%# DataBinder.Eval(Container.DataItem, "some_data")%>
                  </td>
                  <td >
                      <asp:LinkButton Text="Update" class="lnk_showCheck" CommandName="update" Runat="server" ID="update"   />
                  </td>
                  <td >
                      <div id="divCheck" style="display: none">Check</div>

                  </td>
              </tr>
          </table>
      </ItemTemplate>

</asp:DataList>

The idea is that when clicking linkbutton on any row, it has to trigger a server side function and call jquery function ShowCheck.

Protected Sub MyDataList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles MyDataList.ItemCommand

        If e.CommandName = "update" Then
            Dim script As String = "<script language='javascript'> ShowCheck();</script>"
            Page.ClientScript.RegisterStartupScript(Me.[GetType](), "ShowCheck", script, False)

        End If

    End Sub

Jquery ShowCheck() has to show divCheck in that row.

<script type="text/javascript">

        function ShowCheck() {

            //alert($(this).get(0).tagName);
            $('div', $(this).closest("td").next()).show();
            };

    </script>

Problem is that $(this) is passed as an undefined object. It should be passed as a LinkButton object inside DataList.

Is that possible? How could jquery find divCheck in Table row when is triggered from server side function?

Aucun commentaire:

Enregistrer un commentaire