Click here to Skip to main content
15,908,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am bingding value in gridview and i have javascript function i am doing postpack once i find gridview client id. but as i used itemtemplate in table , javscript is not taking client id of gridview id. see below my coding.

JavaScript:
JavaScript
<script type="text/javascript" language="javascript">

function qandans_filter_search(s) {
alert(s);
debugger;
if (s == 5) {
document.getElementById('<%= hiddenval.ClientID %>').value = s;

__doPostBack("<%=girdview1.ClientID%>", "");  // client is not coming. here coming like " table#gridview1 . so, here how to capture gridviewid as client id which stars table#ct.....gridvi..
}
else {
document.getElementById('<%= hiddenval.ClientID %>').value = s;

}
}
</script>


Gridview :
ASP
<asp:GridView ID="girdview1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<p><%# Eval("question") %></td> </p>
</tr>
<tr>
<p><%# Eval("answer") %></td>
</tr>

</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Posted
Updated 22-Jan-14 22:06pm
v2

1 solution

This is horrible in ASP.NET, because ASP.NET is horrible. The best way is to do this

var myGrid = <%theGrid.ClientId %>


And then use myGrid from there. Do the same with all your client ids, have one ugly block that defines these things, and then use the client side variables.
 
Share this answer
 
Comments
christhuxavier 23-Jan-14 5:26am    
thanks for reply. i made the mistake. I fixed that one. if we do not declare AllowPaging="true", it will not work. so, for gridview,listview , we have to declare paging stuff whenever we are accessing id of gridview and listview in Javscript.
Christian Graus 23-Jan-14 16:28pm    
FYI, if you gave me a 1 vote, that is a down vote, 5 is a good vote.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900