【发布时间】:2013-01-21 14:06:04
【问题描述】:
当人们使用GridView 在我的网站上搜索时,我希望有一个checkbox 列,他们单击该列会将名为STATUS 的列中的值更改为U。我正在寻找有效的代码,所以我希望你们能提供帮助。我是一个完全的菜鸟,所以如果你知道答案,请描述一下。
Checkbox 按钮的代码 - 目前,当我搜索时,它返回说它无法将字符串转换为 boolean。
<asp:TemplateField HeaderText="Successful Contact?">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" checked='<%#Bind("status")%>' AutoPostBack="true" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" checked='<%#Bind("status")%>'
Enabled="False" /></ItemTemplate>
</asp:TemplateField>
这是vb代码
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
For Each GridViewRow In GridView1.Rows
Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
Dim value As Boolean
value = DirectCast(GridView1.Rows(e.RowIndex).Cells(0).FindControl("CheckBox1"), CheckBox).Checked
Dim connectionString As String = ConfigurationManager.ConnectionStrings("Data Source=server;Initial Catalog=i3FCC01;Integrated Security=True;").ConnectionString
Dim com_sql As New SqlClient.SqlCommand
Dim insertSql As String
insertSql = "Update CallQueueFCC Set Status='U' where Id = @id"
Using myConnection As New SqlConnection(connectionString)
myConnection.Open()
Dim myCommand As New SqlCommand(insertSql, myConnection)
myCommand.Parameters.AddWithValue("@status", value)
myCommand.ExecuteNonQuery()
myConnection.Close()
End Using
Next
GridView1.EditIndex = -1
DataBind()
End Sub
【问题讨论】: