Sri Sri - 6 months ago 145
Javascript Question

how to get hidden column value in gridview using jquery

in my gridview control i have 4 columns and 1 column is invisible and Email Address Column is Invisible

<asp:GridView id='gridData' runat='server'>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblUsername" runat="server"
Text='<%# Bind("ToUsername") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblfirstname" runat="server"
Text='<%# Bind("Firstname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbllastname" runat="server"
Text='<%# Bind("Lastname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblEmaill" runat="server" visible="false" Text='<%# Bind("EmailAddress") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:Gridview>


this is my JQuery i want to display user details when i click on row along with Email Address

$(function () {

var gridId = "<%= gridData.ClientID %>";
var rowClickEvent = "#" + gridId + " tbody tr"
var current = "";

$(rowClickEvent).click(function () {
var row = this;
var username = row.cells[0].childNodes[1].innerText;
var firstname = row.cells[1].childNodes[1].innerText;
var lastname = row.cells[2].childNodes[1].innerText;
var email = row.cells[3].childNodes[1].innerText;


alert('Username : '+username+'<br/>FullName : '+firstname+""+lastname+'<br/>Email : '+email);
});


i also tried this code but its not working:

var tr = $(this).closest('tr');
var message = row.cells[3].next("input[name$=lblemail]").val();

Answer

visible="false" will not let the control to be rendered at the client side. So when you try to access it in client scripts you won't find it because the element won't exists. If you want to access it at the client side and want it to be hidden always you can use HiddenFields or use CSS to hide that element at the client side by adding display:"none" or visibility:"hidden" or both.

Comments