Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi How to pass rowindex of gridview with id of the image

C#
OnClientClick= '<%# string.Format("CImg(this,\"{0}\");",Container.DataItemIndex) %>' />


not working can any one suggest how to achieve this
Posted
Updated 11-Sep-11 23:58pm
v2
Comments
[no name] 12-Sep-11 4:16am    
your question is not clear.
Code_seeker_ 12-Sep-11 4:22am    
Actually i want to pass both image id and gridview rowindex to javascript function, image is in gridview
Herman<T>.Instance 12-Sep-11 6:04am    
you can retrieve rowinde when using onRowDataBound event

try the following,

OnClientClick="return Call(this)"

assuming ur image ctrl is in Item template and no other nesting elements are there

javascript:

function Call(ctrl)
{
var row=ctrl.parentNode.parentNode;//to get row containing image
var rowIndex=row.rowIndex;//row index of that row.
}


I hope this helps, if not get back to me with more details.
 
Share this answer
 
Comments
Ankur\m/ 12-Sep-11 8:40am    
You have made certain assumptions here like - no other nesting elements are there. A hard-coded code is never recommended. A "generalised" code is the way to go.
 
Share this answer
 
Comments
Ankur\m/ 12-Sep-11 8:34am    
All the methods describe there needs server postback. From the question, it seems the OP is looking for a client-side method.
Check this link out - Get GridView selected row DataKey in Javascript[^].

I guess this is what you are looking for.

BTW, I got this link by a simple Google search - gridview row index javascript[^].

Hope this helps!
 
Share this answer
 
Comments
Anuja Pawar Indore 12-Sep-11 8:59am    
Google search includes post back, directly or in directly javascript they are calling post back :)
Ankur\m/ 12-Sep-11 13:08pm    
I am sorry but I couldn't find any relevance to your comment here.
And my apologies if I said something wrong about your answer. Let me try to explain it again. The link you gave describes methods which need post back. The server then finds and returns the selected row, which is quite a expected behavior. What is tricky is getting the index of selected row at the client side. And the OP exactly wants that. So your answer doesn't actually answer the question.
And yes, Google search does NOT necessarily have full postback. There is a concept called partial post back, which is VERY different from a full postback. It's about performance using a simple theory that send only what is required rather than sending everything and the other way round. You save network bandwidth and thus better performance. Hope that clears it.

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