0

I am facing this situation and have no idea how to solve it. I have Gridview with this columns and this sample values:

CHECKBOX   NAME   SURNAME
-------------------------
Checkbox1  John   Smith
Checkbox2  Jerry  Rose
Checkobx3  Will   Mathews

I have a problem to get value from second column from dynamically created gridview where checkbox is checked. So I check Checkbox2 and now I want to get value from Name column for this row. In this case that would be "Jerry".

Also, if I checked Checkbox1 and Checkbox2 I want to get "John" and "Jerry" split by comma.

My code so far:

    $('#<%=GridView1.ClientID %> tbody >tr >td >input:checked').each(function () {      
           alert($(this).find("td").eq(2).html());
      var values+=$(this).find("td").eq(2).html()+","; //values splitted by comma
    });

Below is my gridview code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
            <Columns>
                <asp:TemplateField HeaderText="Select">
                    <ItemTemplate>
                        <asp:CheckBox ID="chkSelected" runat="server"  />
                    </ItemTemplate>
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                    <HeaderTemplate>
                        <asp:CheckBox ID="chkBxHeader"
                            onclick="javascript:SelectAllCheckboxes1(this);" runat="server" />
                    </HeaderTemplate>
                </asp:TemplateField>

When I run this code results are just "undefined". What is wrong?

Please help me out.

0

1 Answer 1

1

Here is corrected JavaScript code:

var result = $('#<%=GridView1.ClientID %> tr td input[id*="chkSelected"][type=checkbox]:checked').map(function () {

    return $(this).closest('tr').find('td').eq(2).text();

    }).get().join();

Regards, Uros

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.