如题,我想获得如:如编辑时获得的e.Item.ItemIndex
问题是如何在CheckBox事件中获得?

解决方案 »

  1.   

    哪个事件?客户端还是后台?客户端直接访问index就好.
    <asp:CheckBox      index='<%#((DataGridItem)Container).ItemIndex%>'  >
      

  2.   

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
    for (int i = 0; i < this.dataGrid1.Items.Count;i++)
    {
    CheckBox cb = (CheckBox)this.dataGrid1.Items[i].FindControl("checkBox1");
    if (cb != null && cb.UniqueID == ((CheckBox)sender).UniqueID)
    {
    int index = i; //这就是你要的序号
    }
    }
    }
      

  3.   

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
       CheckBox checkBox = (CheckBox)sender;   int index = ((DataGridItem)checkBox.Parent.Parent).ItemIndex;  // Parent的数量视你具体的控件嵌套情况而定   // ..............
    }
      

  4.   

    遍历protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
    for (int i = 0; i < this.dataGrid1.Items.Count;i++)
    {
    CheckBox cb = (CheckBox)this.dataGrid1.Items[i].FindControl("checkBox1");
    if (cb != null && cb.UniqueID == ((CheckBox)sender).UniqueID && cb.Checked == true)
    {
    int index = i; //这就是你要的序号
    }
    }
    }
      

  5.   

    foreach (System.Web.UI.WebControls.DataGridItem dl in this.DataGrid1.Items)
            {
                CheckBox chk = (CheckBox)dl.FindControl("ChkSelect");
                if (chk.Checked)
                {
                    dl.Cells[列].Text
                }
            }