Accept and Delete a row in DataGrid
Hi ,
This is my datagrid code in which drag-drop accept and delete buttons ie,, cmdDelete and cmdAccept are not working.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim strRowId As String
Dim strOption As String
strOption = Request.QueryString("option")
If strOption = "" Then
DataBind1()
ElseIf strOption = "Accept" Then
strRowId = Request.QueryString("rowid")
strConnString = objCsLgateway.GetConnectionString()
conn = objCsDataBase.GetDbConnection(strConnString)
mycommand = New SqlCommand("update tblLogos set status =1 where row_id=" & strRowId, conn)
mycommand.ExecuteNonQuery()
Response.Redirect("LogosbyUsers.aspx", True)
ElseIf strOption = "Delete" Then
strRowId = Request.QueryString("rowid")
strConnString = objCsLgateway.GetConnectionString()
conn = objCsDataBase.GetDbConnection(strConnString)
mycommand = New SqlCommand("delete tblLogos where row_id=" & strRowId, conn)
mycommand.ExecuteNonQuery()
Response.Redirect("LogosbyUsers.aspx", True)
Else
DataBind1()
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Sub DataBind1()
Try
strConnString = objCsLgateway.GetConnectionString()
conn = objCsDataBase.GetDbConnection(strConnString)
Dim adap As New SqlDataAdapter("select * from tblLogos where status=0", conn)
Dim ds As New DataSet
adap.Fill(ds, "tblLogos")
DataGrid1.DataSource = ds
DataGrid1.DataBind()
Catch errEx As Exception
Response.Write(errEx.Message)
Finally
objCsDataBase.CloseDbConnection(conn)
End Try
End Sub
Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
Dim objItem As DataGridItem
For Each objItem In DataGrid1.Items
If objItem.ItemType <> ListItemType.Header And objItem.ItemType <> ListItemType.Footer And objItem.ItemType <> ListItemType.Pager Then
Dim ChkGet1 As Boolean
Dim strRowId
ChkGet1 = CType(objItem.Cells(0).FindControl("chkget"), CheckBox).Checked
strRowId = CType(objItem.FindControl("row_id"), Label).Text
If ChkGet1 = True Then
strConnString = objCsLgateway.GetConnectionString()
conn = objCsDataBase.GetDbConnection(strConnString)
mycommand = New SqlCommand("delete from tblLogos where row_id=" & strRowId, conn)
mycommand.ExecuteNonQuery()
End If
End If
Next
DataBind1()
End Sub
Private Sub cmdAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAccept.Click
Dim objItem As DataGridItem
For Each objItem In DataGrid1.Items
If objItem.ItemType <> ListItemType.Header And objItem.ItemType <> ListItemType.Footer And objItem.ItemType <> ListItemType.Pager Then
Dim ChkGet1 As Boolean
Dim strRowId
ChkGet1 = CType(objItem.Cells(1).FindControl("chkget"), CheckBox).Checked()
strRowId = CType(objItem.FindControl("row_id"), Label).Text
If ChkGet1 = True Then
strConnString = objCsLgateway.GetConnectionString()
conn = objCsDataBase.GetDbConnection(strConnString)
mycommand = New SqlCommand("update tblLogos set status =1 where row_id=" & strRowId, conn)
mycommand.ExecuteNonQuery()
End If
End If
Next
DataBind1()
End Sub
pls read the entire code and help me in rectifying my error.
Regards
Vijayarajan.V
|