我在datagrid的摸班列里放了一个checkbox:
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="编辑" CancelText="取消" EditText="编辑">
<asp:TemplateColumn HeaderText="审核状态">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"audit") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox id=chkAudit Checked='<%#DataBinder.Eval(Container.DataItem,"audit")%>' Runat="server">
</asp:CheckBox>
</EditItemTemplate>
</asp:TemplateColumn>
我想在选中checkbox的后,点”更新“就更新”审核状态“的值(1或0,选中就是1,不选中就是0)。但是我这样写,更新不到数据库里去:
    Sub dgNewsList_UpdateCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles dgNewsList.UpdateCommand
        Dim intKey As Integer = dgNewsList.DataKeys(CInt(e.Item.ItemIndex))
        Dim intCount As Integer '返回更新成功与否,intCount=1表示成功,其他表示失败        Dim chk As CheckBox = CType(dgNewsList.FindControl("chkAudit"), CheckBox)
        chk = New CheckBox
        'Dim ddlPub As DropDownList = CType(dgNewsList.FindControl("ddlPublish"), DropDownList)
        'ddlPub = New DropDownList        Dim sqlConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("ConnStr"))
        Dim strSQL As String = "UPDATE News SET audit=@audit WHERE id=@id"
        Dim Cmd As SqlCommand = New SqlCommand(strSQL, sqlConn)
        If chk.Checked = True Then
            Cmd.Parameters.Add("@audit", SqlDbType.Int).Value = 1
        Else
            Cmd.Parameters.Add("@audit", SqlDbType.Int).Value = 0
        End If
        'Cmd.Parameters.Add("@publish", SqlDbType.Int).Value = ddlPub.SelectedValue
        Cmd.Parameters.Add("@id", SqlDbType.Int).Value = intKey        sqlConn.Open()
        ' Try
        intCount = Cmd.ExecuteNonQuery()
        If intCount = 1 Then
            Response.Write("<script language='javascript'>alert('修改成功!')</script>")
        Else
            Response.Write("<script language='javascript'>alert('修改失败!')</script>")
        End If
        sqlConn.Close()
        'Catch ex As Exception
        '    Response.Write(ex.Message.ToString())
        'End Try
        dgNewsList.EditItemIndex = -1
        BindData()
跟踪的时候checkbox的值老是false.
很急,希望各位帮帮忙!!!!谢谢!!!!!