2010-07-26 158 views
0

我有一個網格視圖有複選框。現在如何在服務器端獲得它的價值。如何獲得價值?

<ItemTemplate> 
    <asp:CheckBox 
    ID="chkEditable" runat="server" AlternateText="Is Editable" 
    OnCheckedChanged="chkEditable_CheckedChanged" 
    AutoPostBack="true" Value='<%# Eval("PK_ID")%>' /> 
</ItemTemplate> 
+0

你是不是想進去或OnCheckedChanged處理程序之外的價值頁面後面的代碼? – 2010-07-26 12:33:11

回答

1
protected void chkEditable_OnCheckedChanged(object sender, EventArgs e) 
     { 
      GridViewRow gv = (GridViewRow)(((Control)sender).NamingContainer); 
      int pk = this.GridView1.DataKeys[gv.RowIndex].Value.ToString(); 
      // Get the reference of this CheckBox 

      CheckBox chk = gv.FindControl("chkEditable") as CheckBox ; 
      //do stuff 

     } 

手動添加事件處理程序