1

I have got a gridview with certain rows/columns and an edit button for each row. When the edit button is clicked, it opens a popup window with a textbox and a button. I want to know the index of the selected row on click of the button inside the popup. I added code like so

var table = document.getElementById('<%= gvTimeSlots.ClientID%>');
var Row;
for (var i = 1; i < table.rows.length; i++) {
    Row = table.rows[i];
    alert(Row);
}

But the alert gives me "Undefined". What am I missing here?

1
  • 3
    Start iterating from 0, not from 1. Commented May 20, 2013 at 6:23

2 Answers 2

5

This is my fix..

function GetSelectedRow(lnk) {
        var row = lnk.parentNode.parentNode;
        var rowIndex = row.rowIndex - 1;
        alert("RowIndex: " + rowIndex);
        return false;
    }

I am calling this function in Onclientclick event of the link button.

<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="10%" Visible="true">
     <ItemTemplate>
          <asp:LinkButton ID="lnkViewTimeSlots" runat="server" Text="Edit" ForeColor="Blue" OnClick="lnkViewTimeSlots_click" OnClientClick="return GetSelectedRow(this); javascript:shouldsubmit=true;" CausesValidation="false" Style="padding: 0px; margin: 0px;"></asp:LinkButton>
     </ItemTemplate>
 </asp:TemplateField>
Sign up to request clarification or add additional context in comments.

Comments

1

Simply you can get the row index like

function GetSelectedRow(lnk) {
        alert("RowIndex: " + lnk.$index;);//This lnk.$index will get the index 
        return false;
    }

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.