1

我有一个gridview,我想将rowindex 值传递给javascript。我尝试使用以下代码,但它不起作用。

在网格视图中

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

在 Javascript 中:

function checkSts(i) {  alert(i); }
4

2 回答 2

1

您可以将其键入为

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

和工作。

替代asp:checkbox

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

和后面的代码

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

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

既检查又有效。

于 2012-10-24T07:23:34.970 回答
0

您可以rowindex通过使用parentElement到达特定元素嵌套的行来获取元素

例如。

onclick="callme(this)"

function callme(obj)
{
  obj.parentElement.parentElement.rowIndex--- this wud be rowindex of the row.
}
于 2012-11-27T14:28:20.857 回答