我的数据显示正常,CheckBox也显示正常,就是选择的时候cmdfindselected_Click发生后
if(chkExport.Checked)//这一步是false,我明明选上了呀请教高手<asp:TemplateColumn HeaderText="操作">
<HeaderStyle HorizontalAlign="Center" Width="50px"></HeaderStyle>
<ItemTemplate>
<input type="hidden" id="SelectedID" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "username")%>' NAME="SelectedID" />
<asp:CheckBox ID="chk" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>//以下是设计的代码private void cmdfindselected_Click(object sender, System.EventArgs e)
{
//同意 System.Web.UI.WebControls.CheckBox chkExport;
//string sID;
string sql="未选择";
System.Collections.ArrayList oExArgs = new System.Collections.ArrayList();
foreach(DataGridItem oDataGridItem in DataGrid1.Items)
{
chkExport = (CheckBox)oDataGridItem.FindControl("chk");
if(chkExport.Checked)//
{
//如果要进行删除,可以在这里构造sql语句进行删除
 sql = "updata FROM Document WHERE id =" 
+ ((HtmlInputHidden)oDataGridItem.FindControl("SelectedID")).Value;
//Label2.Text += "<li>" + sql; 
//sID = ((HtmlInputHidden)oDataGridItem.FindControl("SelectedID")).Value;
//oExArgs.Add(sID);
//int i = 0;
//Label1.Text = "";
//for( i = 0;i<oExArgs.Count;i++)
//{
//Label1.Text += oExArgs[i] + "<br>";
//}
ERR.Text=sql;
}
ERR.Text+=sql;
}
}

解决方案 »

  1.   

    http://www.chinabs.net/aspnet/default.asp
      

  2.   

    <asp:CheckBox ID="chk" AutoPostBack="True" Runat="server" />
      

  3.   

    把你 绑定数据的部分放到
    if(!IsPostBack)
    {
    'Bind data here 
    }
      

  4.   

    http://community.csdn.net/Expert/topic/3347/3347014.xml?temp=2.911013E-02
      

  5.   

    private void BtSubmit_Click(object sender, System.EventArgs e)
    {
    string idl="";
    foreach(DataGridItem Dgi in DG_Main.Items)
    {
    CheckBox CB=(CheckBox)Dgi.Cells[6].Controls[1];
    if(CB.Checked)
      idl+=DG_Main.DataKeys[Dgi.ItemIndex].ToString()+",";
    }
    if(idl!="")
    {
    idl=idl.Substring(0,idl.Length-1);
    idl="'" + idl.Replace(",","','") + "'";
    Update(idl);
    }
    else
    {
    Response.Write("<script language=javascript>alert('请选中要审批的记录!');history.go(-1);</script>");
    }
    DGBind();
    }private void Update(string InId)
    {
    string StrCmd="delete from table where ArtNo in(" + InId + ")";
    DBOperate DBO = new DBOperate();
    DBO.ExcSQL(StrCmd);
    }
      

  6.   

    请教楼上CheckBox CB=(CheckBox)Dgi.Cells[6].Controls[1];这句话是什么意思呀,我怀疑问题是我没有找到指定的CheckBox!
      

  7.   

    http://blog.csdn.net/lovecherry/archive/2005/03/01/306243.aspx
      

  8.   

    foreach (DataGridItem i in MyDataGrid.Items) 
    {
    CheckBox SelectChkBxItem = (CheckBox) i.FindControl ("SeleteThis");
    if (SelectChkBxItem.Checked) 
    {
    your code;
    }}
      

  9.   

    代码没有放在if(!ispostback){}里面造成的。
      

  10.   

    if( !IsPostBack )
    {
     
    }