Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 19th, 2006, 01:31 PM
Authorized User
 
Join Date: Sep 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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





 
Old September 19th, 2006, 01:39 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Dont double post.

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 19th, 2006, 02:00 PM
Authorized User
 
Join Date: Sep 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok i like to get the Answer immediately. plz help in getting me through.

Regards
Vijay

 
Old September 19th, 2006, 02:15 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It may have to do with how you are calling your databinds on post back. Posting twice will nto get you a respone, regardless ifyou need the answer immediately or not.

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Accept and Delete a row in DataGrid vijay_83 ASP.NET 1.0 and 1.1 Basics 2 September 19th, 2006 12:15 PM
how delete row in datagrid which check checkbox ashish2001mca Forum and Wrox.com Feedback 1 September 18th, 2005 03:43 AM
Confirm delete row in datagrid rajanikrishna General .NET 3 December 8th, 2004 09:27 PM
how to delete a row when click delete hyperlink naveenkumarg1 Pro JSP 1 August 16th, 2004 01:29 AM
Manage data row by row in datagrid Dragonist Classic ASP Databases 5 July 29th, 2004 04:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.