2010-07-26 160 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 

     } 

手动添加事件处理程序