locked
To get grid name RRS feed

  • Question

  • User1126057398 posted

    On page, there are 2 grids containing 2 dropdown each. To get dropdown value, I am using onchange event and storing it in hidden value like:

    $(.classDropDown).change(function(){

     $('#<%=hfSelectedValue.ClientID%>').val( this.value);

    });

    In the above .classDropDown is the class defined on dropdown.

    How can I get dropdown's grid name and how can I get column index?

    Thursday, August 25, 2016 12:45 PM

All replies

  • User-1142886626 posted

    Hi Geetasks,

    If you want get the name of gridview. You could use the click event, then use jQuery traversing methods to select element. Such as find (), parent (), eq () and so on.

    Code below is for your reference:

    <script type="text/javascript">
            $(function () {
                    $("tr").click(function () {
                        var a = $(this).find("td").eq(2).eq(0).text();
                        alert(a);
                        var b = $(this).parent().parent().attr("id");
                        alert(b);
                    })
            })
        </script>
    <body>
        <form id="form1" runat="server">
         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            ID
                        </HeaderTemplate>
                        <ItemTemplate>   
                            <asp:Label ID="lbldes" runat="server" Text='<%#Eval("ID") %>'></asp:Label>                     
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            Owner
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lbldes" runat="server" Text='<%#Eval("Owner") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            RegNo
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server">
                              <asp:ListItem>1</asp:ListItem>
                                <asp:ListItem>2</asp:ListItem>
                                <asp:ListItem>3</asp:ListItem>
                                <asp:ListItem>4</asp:ListItem>
                            </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </form>
    </body>
    

    Best Regards,

    Ailleen

    Friday, August 26, 2016 11:50 AM