Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a gridview with 3 textbox item templates (3 Columns).
I want to get active row index of gridview on last columns(TextBox3's) blur event in javascript.
How to catch the CurrentRowIndex and pass it to Javascript Function?

Please Help !!!

Thanking In Anticipation !

<asp:TextBox ID="T3" runat="server" onblur="getIndex(this.rowindex ?????);">
.
.
.
function getIndex(index)
{
    alert(index);
}
Posted
Updated 25-Apr-11 1:33am
v2

One way, You can add the currentrowindex as a custom attribute to your textbox in RowDataBound event of the Grid. You will the index easily at this event add it as attribute. Now you can access the same attribute at javasctipt as

<asp:TextBox ID="T3" runat="server" onblur="getIndex(this);">

function getIndex(curObj)
{
    var index = curObj.getAttribute('currentrowindex ');
}
 
Share this answer
 
Comments
Prasad131 27-Apr-11 1:45am    
Thanks Brij, for replying !
On the ItemDataBound of the GridView event you can write like that
This is for data grid so convert it to Gridview

protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || 
                 e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ((TextBox)e.Item.FindControl("txt1")).Attributes.Add("onblur", "getIndex(" +                        e.Item.ItemIndex + ")"); 
            }
        }
 
Share this answer
 
Comments
Prasad131 27-Apr-11 1:44am    
Thank U So much Singh !!! U r really King !!!
It works perfect as i needed.

Thank u so much!!
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.
}
 
Share this answer
 
Comments
CHill60 25-Feb-15 4:57am    
Question is nearly 4 years old and already resolved

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