To delete and Accept 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
but in my datagrid i have 2 accept and delete buttons.one accept and one delete hyperlink buttons are bound to datagrid and another one delete and accept are drag and drop controls. hyperlink buttons are used for deleting and accepting single row and drag-drop controls are used for deleting and accepting multiselect checkboxes. In that hyperlink controls are working properly. but the chkGet command in cmdDelete and cmdAccept are showing false although checked in F11. For that i need our help and suggestions.
pls read the entire code and help me in rectifying my error.
Thanx in Advance
Vijay
|