1

I have a gridview and i want to pass rowindex value to javascript. I tried with following code but its not working.

In Gridview

<asp:TemplateField>
     <ItemTemplate>
        <asp:CheckBox ID="chkSelect" runat="server"  onclick="javascript:return checkSts('<%# DataBinder.Eval(Container.DataItemIndex) %>')" />
     </ItemTemplate>
</asp:TemplateField> 

In Javascript:

function checkSts(i) {  alert(i); }
1
  • plz, can you post your code.. Commented Oct 24, 2012 at 6:55

2 Answers 2

1

You can type it as

<input type="checkbox" onclick="return checkSts('<%#Eval("FieldName")%>')" />

and work.

Alternative with asp:checkbox

<asp:CheckBox runat="server" ID="chBEna" onclick='<%#getCode(Container.DataItem)%>' />

and on code behind

protected string getCode(object oItem)
{
    string cPid = DataBinder.Eval(oItem, "FieldName").ToString();

    return "return checkSts('" + cPid + "')";
}

both checked and works.

Sign up to request clarification or add additional context in comments.

4 Comments

Aristos, i wants to process everything on client side. for example if i have 100 rows i dont to go every time on server side when i click check box
@user1645200 what do you mean ? (lost you here)
Aristos, i wants to process everything on client side. for example if i have 100 rows i dont to go every time on server side when i click check box
@user1645200 Ok, now I understand that you do not understand what the code do. So simple use it and you see :) - this code is render what you going to do on client side - is not processing on code behind anything. The function I use on code behind is for rendering, because is difficult (at least I do not know how) to render this code direct.
0

You can get rowindex of element by using parentElement to reach to the row in which particular elemnt is nested

eg.

onclick="callme(this)"

function callme(obj)
{
  obj.parentElement.parentElement.rowIndex--- this wud be rowindex of the row.
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.