Answered by:
how to get input of type image in first cell of the gridview row using jquery

Question
-
User1873097007 posted
Hiall,
I want to change src of imagebutton on outside checkbox check., the image button is in 1st column/cell of gridview along with one label also in the same cell.
I want to do this using jquery but I dont know the syntax much.
I'm trying following but not getting success:
in for loop:
$(Rows[row]).children('td:nth-child(1)')[0].childNodes[0].src = "images/minus.gif"; $(Rows[row]).children('td:nth-child(0)').children('input[type=image]').attr("src", "images/minus.gif");
Above two lines not showing imagebutton in childNodes collection but I can see label in the collection at 0th position or child.
any help??
Wednesday, March 9, 2016 10:28 AM
Answers
-
User61956409 posted
Hi sameerpantvaidya,
I want to change src of imagebutton on outside checkbox check., the image button is in 1st column/cell of gridview along with one label also in the same cell.You could refer to the following sample code to dynamically change ImageUrl of ImageButton within GridView.
<script> $(function () { $("#mychk").change(function () { var ischecked = $(this).is(":checked"); //alert(ischecked); if (ischecked) { $("#<%=GridView1.ClientID%>").find("tbody tr:not(:first-child) td:first-child input[type=image]").attr("src", "../../Images/orderedList1.png"); } else { $("#<%=GridView1.ClientID%>").find("tbody tr:not(:first-child) td:first-child input[type=image]").attr("src", "../../Images/orderedList0.png"); } }) }) </script>
<asp:CheckBox ID="mychk" runat="server" /> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="Column1"> <ItemTemplate> <asp:ImageButton ID="mybtn" runat="server" ImageUrl="~/Images/orderedList0.png" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Column2"> <ItemTemplate> <asp:Label ID="lbldata" runat="server" Text='<%#Eval("field") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 10, 2016 8:49 AM
All replies
-
User1686483761 posted
Hi sameer,
I'm trying following but not getting success:Could you please share your related code with us so that we could reproduce your problem?
Thursday, March 10, 2016 3:43 AM -
User61956409 posted
Hi sameerpantvaidya,
I want to change src of imagebutton on outside checkbox check., the image button is in 1st column/cell of gridview along with one label also in the same cell.You could refer to the following sample code to dynamically change ImageUrl of ImageButton within GridView.
<script> $(function () { $("#mychk").change(function () { var ischecked = $(this).is(":checked"); //alert(ischecked); if (ischecked) { $("#<%=GridView1.ClientID%>").find("tbody tr:not(:first-child) td:first-child input[type=image]").attr("src", "../../Images/orderedList1.png"); } else { $("#<%=GridView1.ClientID%>").find("tbody tr:not(:first-child) td:first-child input[type=image]").attr("src", "../../Images/orderedList0.png"); } }) }) </script>
<asp:CheckBox ID="mychk" runat="server" /> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="Column1"> <ItemTemplate> <asp:ImageButton ID="mybtn" runat="server" ImageUrl="~/Images/orderedList0.png" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Column2"> <ItemTemplate> <asp:Label ID="lbldata" runat="server" Text='<%#Eval("field") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 10, 2016 8:49 AM