如何根据radgrid里面的dropdownlist值更新表?

时间:2012-05-12 12:44:40

标签: asp.net sql-server vb.net telerik radgrid

当我在radgridrow项目中选择dropdownlist的值时,我的此代码无法更新表的approve列,这是错误的。

Imports Telerik.Web.UI
Imports System.Data.SqlClient
Dim constr As String = "Data Source=DINFOSYSTEMS\SQLEXPRESS;Initial Catalog=app;Integrated Security=True"

    Protected Sub RadGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
            For Each item As GridDataItem In RadGrid1.MasterTableView.Items
                Dim drop As DropDownList = TryCast(item.FindControl("DropDownList1"), DropDownList)
                Dim ids As HiddenField = TryCast(item.FindControl("HiddenField1"), HiddenField)
                Try
                    Using conn = New SqlConnection(constr)
                        Using cmd = conn.CreateCommand()
                            conn.Open()
                            Dim sql As String = "UPDATE app SET approve = @approve WHERE id = @id"
                            cmd.CommandText = sql
                            cmd.Parameters.AddWithValue("@approve", drop.SelectedValue)
                            cmd.Parameters.AddWithValue("@id", ids.Value)
                            cmd.ExecuteNonQuery()
                        End Using
                    End Using
                Catch ex As Exception
                    Response.Write(ex.Message)
                End Try

            Next
        End Sub

0 个答案:

没有答案