如何捕获ActiveRowIndex并将其传递给Javascript函数? [英] How to catch the ActiveRowIndex and pass it to Javascript Function?

查看:144
本文介绍了如何捕获ActiveRowIndex并将其传递给Javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有3个文本框项目模板的gridview(3列)。

我想在javascript中的最后一列(TextBox3)模糊事件中得到gridview的活动行索引。

如何捕获CurrentRowIndex并将其传递给Javascript函数?



请帮助!!!



感谢期待!



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);
}

推荐答案

单向,您可以将currentrowindex作为自定义属性添加到Grid的RowDataBound事件中的文本框中。您将在此事件中轻松将索引添加为属性。现在你可以在javasctipt上访问相同的属性



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 ');
}


在GridView事件的ItemDataBound上你可以像这样编写

这是用于数据网格所以转换它到Gridview



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 + ")"); 
            }
        }


尝试以下操作,



OnClientClick = 返回电话(这个)



假设您的图像ctrl在项目模板中,没有其他嵌套元素存在



javascript:



函数调用(ctrl)

{

var row = ctrl.parentNode .parentNode; //获取包含图像的行

var rowIndex = row.rowIndex; //该行的行索引。

}
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.
}


这篇关于如何捕获ActiveRowIndex并将其传递给Javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆