Get Grid View Hidden Field Value Using Javascript/jquery
Forgive my English, I had one challenge in my project I,e whenever I started to access hidden field value which in grid view using JavaScript or Jquery, I'm getting compilation err
Solution 1:
I'm not sure the code
document.getElementById("<%=PatientRefferalId.ClientID%>")
will work, because you don't have only one "PatientRefferalId", but you get many (as many as numbers of rows in your gridview).
I don't know if there is a cleaner way, but I can do what you want by using this javascript code
var gv = document.getElementById("<%=gvPatient.ClientID%>");
var Rows= gv.getElementsByTagName("tr"); //Getall the rowsfrom your gridview (rendered as html table).
// you can loop through the rowsor if you know the row index, you can do:
alert(Rows[2].childNodes[0].children[0].value); //Show you the first control (the hiddenfield) of the first cell of the row #2.
Solution 2:
Hi This post may help you.
var c = document.getElementsByTagName("table");
for (var i = 0; i < c.length; i++) {
if (c[i].id.indexOf("GridView1") > -1) {
var hidd = c[i].getElementsByTagName("input");
for (var j = 0; j < hidd.length; j++) {
if (hidd[j].type == "hidden")
alert(hidd[j].id);
}
}
}
And also refer following link .. its working to me..
Solution 3:
<asp:ContentID="Content2"ContentPlaceHolderID="cphContent"runat="Server"><scripttype="text/javascript">functionDispValue(btnShow) {
var parentRow = $(btnShow).closest("tr");
var hiddenField=parentRow.find('input[id$=PatientRefferalId]');
alert(hiddenField.val());
returnfalse;
}
</script><divalign="left"style="float: left; margin-left: 5px;"><asp:GridViewID="gvPatient"runat="server"AutoGenerateColumns="false"EnableViewState="true"><Columns><asp:TemplateFieldHeaderStyle-Font-Bold="true"HeaderStyle-Font-Size="12px"HeaderStyle-Height="20px"><HeaderTemplate> Patient Name </HeaderTemplate><ItemTemplate><asp:HiddenFieldID="PatientRefferalId"runat="server"Value="0" /><asp:LinkButtonID="lnkPopUp"runat="server"Style="font-size: 16px;"OnClientClick="return DispValue(this)"Text="PopUp"
></asp:LinkButton></ItemTemplate></asp:TemplateField></Columns></asp:GridView></div></asp:Content>
Post a Comment for "Get Grid View Hidden Field Value Using Javascript/jquery"