Calling a jquery function from a datalist

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="check" style="display: none">Check</div>
                      
                  </td>
              </tr>
          </table>
      </ItemTemplate>

</asp:DataList>

Open in new window


The idea is that when clicking linkbutton on any row, divCheck of that row has to be shown.

For that, when linkbutton is clicked, it calls a jquery function for showing a div.
<head>
    <script type="text/javascript">
        jQuery(function ($) {
            $('a.lnk_showcheck').click(function (e) {
                e.preventDefault();
                $('#check').show();
            });
        });
    </script>
</head>

Open in new window


However, it only shows div of first record. If I click Linkbutton on any other record, div doesn't show. I suppose it has to be with div ID name. How could I achieve this requirement?

Thanks
LVL 1
miyahiraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
this is due to ASP.NET generating unique client ids for each element In the repeater.
But the following should(!) work:
<head>
    <script type="text/javascript">
        jQuery(function ($) {
            $('a.lnk_showcheck').click(function (e) {
                e.preventDefault();
                $('div',$(this).closest("td").next()).show();
            });
        });
    </script>
</head>

Open in new window


Otherwise could you please post/attach the generated HTML source or reproduce the HTML content in http://jsbin.com ?

Thanks and HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
miyahiraAuthor Commented:
It works !
However, and this is other question and not related with the first one, after calling jquery function, LinkButton doesn't trigger this server side function.
Why?
Protected Sub MyDataList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles MyDataList.ItemCommand

        If e.CommandName = "update" Then
            ' Put code here
            ' It doesn't trigger after LinkButton calls jquery function.

        End If

    End Sub

Open in new window

0
Rainer JeschorCommented:
Hi,
OK. Normally you should open another question as this is a "new" one (and referencing this question).

Have you tried already with removing the line
e.preventDefault();

Open in new window

?

HTH
Rainer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.