2010-09-21 24 views

回答

0

好,我找到了一個巧妙的解決辦法:)在的CheckedChanged事件我只是寫了以下內容:

((GridViewRow)((Control)sender).Parent.Parent).DataItemIndex; 
+0

這幾乎完全是布萊恩所說的做的...... – Josh 2010-09-21 13:37:16

1

你可以通過Parent屬性,儘管你必須做一些像chk.Parent.Parent等等。我不知道當前行有多少家長引用是...

HTH。

0

嘗試這樣:

<script language="javascript" type="text/javascript"> 


     function rowno(rowindex) { 
      var gridViewCtlId = document.getElementById("<%=GridView2.ClientID %>").rows[rowindex].cells[1].innerText; 
      alert('you clicked on ' + gridViewCtlId); 
     } 

    </script> 

<asp:GridView ID="GridView2" runat="server" OnRowDataBound="GridView1_RowDataBound1" PageSize="5"> 
     <Columns> 
      <asp:TemplateField> 
       <ItemTemplate> 
        <%--<asp:Button ID="Button1" runat="server" Text="Button" />--%> 
        <asp:CheckBox ID="CheckBox1" runat="server" /> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 
中的.cs

protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e) 
     { 
      if (e.Row.RowType == DataControlRowType.DataRow) 
      { 
       CheckBox delete = (CheckBox)e.Row.Cells[0].Controls[1]; 
       delete.Attributes.Add("onclick", "javascript:rowno(" + count + ")"); 
       count++; 
      } 
     } 
相關問題