ASPX page code: Get the Drop-down box and the value in the text box in the clicked line by clicking a tag in the GridView
Copy Code code as follows:
<asp:gridview id= "GridView1" runat= "Server" >
<Columns>
<asp:boundfield headertext= "id" datafield= "id"/>
<asp:boundfield headertext= "Name" datafield= "ID"/>
<asp:boundfield headertext= "Url" datafield= "ID"/>
<asp:TemplateField>
<ItemTemplate>
<asp:dropdownlist id= "DropDownList1" runat= "Server" >
<asp:listitem value= "0" > Privacy </asp:ListItem>
<asp:listitem value= "1" > Male </asp:ListItem>
<asp:listitem value= "2" > Women </asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:textbox id= "txtdate" runat= "Server" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<a href= "#" onclick= "Save (this);" >Save</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
jquery Code:
Copy Code code as follows:
<script src= ". /scripts/jquery-1.4.1.js "type=" Text/javascript "></script>
<script language= "javascript" type= "Text/javascript" >
function Save (obj) {
var tr = $ (obj). Parent (). parent (); Get the TR for the clicked Line
Tr.find ("TD"). EQ (3). Find ("select"). Val (); Get the fourth column in the clicked row DropDownList1 Select Value
Tr.find ("TD"). EQ (3). Find ("select"). Text (); Get the fourth column in the hit line DropDownList1 select text
Tr.find ("TD"). EQ (4). Find ("Input"). Val (); Get the fourth column TextBox Text in the clicked row
}
</script>