Retrieve Listview values - Getelementbyid

Asked

Viewed 105 times

0

Good night! I have a listview and I am displaying the values inside Span’s, I would like to take the value of span when clicking but as Span’s have the same ID I always get the same value.

Does anyone have any idea how to get around this?

<script>

      function controle(e) {

          var outros = document.getElementById('ooooo').textContent;

          alert(outros);






      }

  </script>

<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">


<EmptyDataTemplate>
    <table style="" runat="server">
        <tr>
            <td>Nenhum dado foi retornado.</td>
        </tr>
    </table>
</EmptyDataTemplate>



<ItemTemplate>



      <span class='fc-event' ID="ooooo" onclick="controle()"><%# Eval("Expr1") %></span>  

</ItemTemplate>



<LayoutTemplate>
    <table runat="server">
        <tr runat="server">
            <td runat="server">
                <table runat="server" id="itemPlaceholderContainer" style="" border="0">

                    <tr runat="server" id="itemPlaceholder"></tr>
                </table>
            </td>
        </tr>
        <tr runat="server">
            <td runat="server" style="">
                <asp:DataPager runat="server" ID="DataPager1" PageSize="25">
                    <Fields>
                        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False"></asp:NextPreviousPagerField>
                        <asp:NumericPagerField></asp:NumericPagerField>
                        <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False"></asp:NextPreviousPagerField>

                    </Fields>
                </asp:DataPager>
            </td>
        </tr>
    </table>
</LayoutTemplate>
<SelectedItemTemplate>
    <tr style="">
        <td>

    </tr>
</SelectedItemTemplate>

        </div>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:COEX_RPBConnectionString %>' SelectCommand="SELECT PROJETO + ' - ' + TITULO AS Expr1 FROM tbl_obras_projetos_final WHERE (STATUS_USUARIO = 'Execução')"></asp:SqlDataSource>
  • because you didn’t use the controller to do that?

  • Because I need to list all the values, then I get the data by clicking and plotting on a map. Hence the need to list all the data.

  • I said the following! why didn’t you use the component?

  • Excuse my ignorance, but can you send a supporting documentation or an example? I really am Noob

  • <span class='fc-event' ID="ooooo" onclick="controle()"><%# Eval("Expr1") %></span> the problem is here ?

  • Exact. It displays more than 200 results but when clicking on one of them I always get the value of the first one using the control function()

  • I can see your javascript control() ?

  • <script> Function control(e) { var others = Document.getElementById('ooooo'). textContent; Alert(others); } </script>

Show 3 more comments

1 answer

0

Set it up like this?

function controle(obj) 
{
	var outros = obj.textContent;
	alert(outros);
}
<label onclick="controle(this);">Número 1</label><br /><br />
<label onclick="controle(this);">Número 2</label><br /><br />
<label onclick="controle(this);">Número 3</label><br />

and on that label:

<span class='fc-event' ID="ooooo" onclick="controle(this)">
    <%# Eval("Expr1") %>
</span>

or

function controle(value) {
  alert(value);
}
<label onclick="controle('Número 1')"> Número 1</label>
<br /><br />
<label onclick="controle('Número 2')"> Número 2</label>
<br /><br />
<label onclick="controle('Número 3')"> Número 3</label><br />

<span class='fc-event' ID="ooooo" onclick="controle('<%# Eval("Expr1") %>')">
    <%# Eval("Expr1") %>
</span>
  • 1

    Virgil Novic in 30 I test and return you.

  • I am sending the email now . It worked out the code you sent.

  • @Pedrovanderlansantana excludes these comments ok!

  • What if I want to change the color of the element I clicked? Before I used Document.getElementByID()

  • I sent the e-mails unfortunately I sent without the subject.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.