Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to get the gridview selected index in javascipt
i have a gridview with n number of rows each row with two checkboxes

by checking the first check box i have to enable the second checkbox fro that i need selected index of gridview first

Thanks in advance
Posted

Hi Yedhuvamshi,

As much I understand your problem, you have to write the following lines of code in RowCreated event of your Gridview:-

C#
if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", String.Format("EnableCheckBox({0});",e.Row.RowIndex));
            }


And then in your Javascript code:-

function
EnableCheckBox(vRowIndex)
{
   // write your code to check the second check box
}
 
Share this answer
 
Suppose the first check box has an id chk.

then here what you could do:

JavaScript
chk.Attributes.Add("onclick","getindex(this.id)")

and then

function getindex(id)
{
 var index = document.getElementById(id).selectedIndex;
 }

pls check this.
 
Share this answer
 
v2
Comments
yedhuvamshi 7-Nov-14 3:42am    
index is saying undefined..
i want to access the second check box..

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