在前台代码如下
<asp:TemplateColumn HeaderText="选中修改">
<ItemTemplate>
<input type="hidden" id="Selectedtime" runat="server" 
   value='<%# DataBinder.Eval(Container.DataItem, "aimtime")%>' NAME="Selectedtime"/>
<asp:CheckBox ID="chkExport" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
后台代码
if( chkExport.Checked)
{
 SqlConnection oSQLConn = new SqlConnection();
 oSQLConn.ConnectionString="Data Source=CAINIAO;Initial Catalog=dayang;User Id=sa;Password=11111";
 string s;
 s = ((HtmlInputHidden)oDataGridItem.FindControl("Selectedtime")).Value;
 string sql;
 sql="delete from xuke where aimtime = "+s;
         System.Data.SqlClient.SqlCommand delcmd=new SqlCommand(sql,oSQLConn);
oSQLConn.Open();
  }
请问我哪儿错拉?
急死我拉,解决了立马给分

解决方案 »

  1.   

    急啊,急啊,会的GGJJMMDD们快帮我啊
      

  2.   

    sureYou must use FindControl and then add function to your check box
    Like this:<asp:datagrid id="dgModules" runat="server">
       <Columns>
          <asp:TemplateColumn HeaderText="读">
    <ItemTemplate>
      <asp:CheckBox id="chkRead" OnCheckedChanged="readChk_Click" 
                    AutoPostBack="True" Checked='<%# getAuthor1(DataBinder.Eval    
                    (Container.DataItem, "author").ToString()) %>' runat="server">
      </asp:CheckBox>
    </ItemTemplate>
          </asp:TemplateColumn>
          <asp:TemplateColumn HeaderText="写">
    <ItemTemplate>
      <asp:CheckBox id="chkWrite" OnCheckedChanged="WriteChk_Click" 
                    AutoPostBack="True" Checked='<%# getAuthor2(DataBinder.Eval
                    (Container.DataItem, "author").ToString()) %>' runat="server">
      </asp:CheckBox>
            </ItemTemplate>
         </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>
    ======================================================
    //设置 读权限 , 写权限为 False
    public void readChk_Click(object sender, System.EventArgs e)
    {
    CheckBox chkAuthorR,chkAuthorW;
    chkAuthorR = (CheckBox)sender;
    if (chkAuthorR.Checked) 
    {
    chkAuthorW = (CheckBox)chkAuthorR.FindControl("chkWrite");
    chkAuthorW.Checked = false;
    }
    lblMsg.Text = "";
    }//设置写权限, 读权限为 False
    public void WriteChk_Click(object sender, System.EventArgs e)
    {

    CheckBox chkAuthorR,chkAuthorW;
    chkAuthorW = (CheckBox)sender;
    if (chkAuthorW.Checked) 
    {
    chkAuthorR = (CheckBox)chkAuthorW.FindControl("chkRead");
    chkAuthorR.Checked = false;
    }
    lblMsg.Text = "";
    }
      

  3.   

    CheckBox 的属性里autopostback 设为 true 感觉你的那个处理事件应该放在 CheckBox 的CheckedChange 事件里判断更好
      

  4.   

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

  5.   

    加上
    if(!this.IsPostBack)
     chkExport.Checked !)
    应该就可以了,要不就是没有绑定事件代码或自动回传没有设成真。
      

  6.   

    做个循环,我用的是C#,看看吧,改写一下就行了,我这可以删除多行
    for(int j=0;j<DataGrid1.Items.Count;j++)
    {
              if(((CheckBox)DataGrid1.Items[j].FindControl("CheckBox1")).Checked)
    string d=DataGrid1.Items[j].Cells[1].Text.ToString();
    db2con.Open();
    OleDbCommand delcmd=new OleDbCommand("delete from stu where stuId='"+d+"'",db2con);
    delcmd.ExecuteNonQuery();
    d=null;
    db2con.Close();
      

  7.   

    没用,autoPostBack设置为true之后,CHECKBOX就无法选中,奇怪了
    现在检查出,CHECKBOX选中后,服务器端没收到这个操作
      

  8.   

    参考:
    http://dotnet.aspx.cc/ShowDetail.aspx?id=FF130C7F-3650-4DA6-8943-8AA4AF3E3459
      

  9.   

    wangdequan1024(紫夜) 
    我就是看的孟子老大的例子做不出来啊
      

  10.   

    http://community.csdn.net/Expert/topic/3427/3427702.xml?temp=.2508966
      

  11.   

    现在就是CHECKBOX选中后,服务器端接收不到,autoPostBack设置为true之后,CHECKBOX就无法选中
    如果本来就把CHECKBOX设置为Checked,则还可以,我再弄一帖,大家帮帮我!!!