Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My Data Grid doesnt call the correct procedure on Delete.

Status
Not open for further replies.

MayoorPatel

Programmer
Apr 10, 2006
35
GB
Hi there I have a datagrid

Code:
<trans:groupedgrid id="DecisionGrid" runat="server" EnableViewState="False" AutoGenerateColumns="False"
		AllowCustomSorting="True" CssClass="search-results-table percent80" AllowRowHighlighting="True"
		RemoveRedundantBorders="False" ReorganiseItemStyles="True" UseAccessibleHeader="True">
		<Columns>		
			
			<asp:BoundColumn DataField="decision_datetime" SortExpression="decision_datetime" HeaderText="Date of Hearing"></asp:BoundColumn>
			<asp:BoundColumn DataField="applicant" SortExpression="applicant" HeaderText="Applicant"></asp:BoundColumn>
			<asp:BoundColumn DataField="respondent" SortExpression="respondent" HeaderText="Respondent"></asp:BoundColumn>
			<asp:BoundColumn DataField="title_no" SortExpression="title_no" HeaderText="Title No"></asp:BoundColumn>
			<asp:BoundColumn DataField="category" SortExpression="category" HeaderText="Category"></asp:BoundColumn>
			<asp:BoundColumn DataField="subcategory" SortExpression="subcategory" HeaderText="Subcategory"></asp:BoundColumn>
			<asp:BoundColumn DataField="is_published" SortExpression="is_published" HeaderText="Published"></asp:BoundColumn>
			<asp:BoundColumn DataField="judgmentid" visible="false" SortExpression="judgementid" HeaderText="Judgement ID"></asp:BoundColumn>	
			<asp:ButtonColumn Text="Delete" CommandName="Delete">
				<itemstyle HorizontalAlign="Center" />
			</asp:ButtonColumn>
		</Columns>
	</trans:groupedgrid><trans:pager id="PagerControl" runat="server" cssclass="normal-table white percent80"></trans:pager>

Which on clicking the delete link should call this procedure

Code:
Private Sub SubCatDataGrid_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DecisionGrid.DeleteCommand

        Dim DecIDLabel As Label = e.Item.FindControl("DecIDLabel")
        If Not DecIDLabel Is Nothing Then
            Me.DeleteDecision(DecIDLabel.Text)
        End If
    End Sub

However when I click the delete button it just posts back to the form. Debuging trace also shows it goes no where near that procedure despite me specifying the "Handles DecisionGrid.DeleteCommand"

Im tearing my hair out over this as I just cant understand why it wont call the procedure, can anyone help?
 
You need to add OnDeleteCommand="Delete" to your <trans:groupedgrid> opening tag attributes
 
Hi there have made some changes to my sub (the name of it has changed to DecisionGrid_DeleteCommand ), shouldn't the delete command fire this sub automatically?

Code:
Private Sub DecisionGrid_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DecisionGrid.DeleteCommand

        Dim DecIDLabel As Label = e.Item.FindControl("DecIDLabel")
        If Not DecIDLabel Is Nothing Then
            Me.DeleteDecision(DecIDLabel.Text)
        End If
    End Sub

Instead when i click on delete it fires

Code:
 Private Sub DecisionGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DecisionGrid.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            e.Item.Attributes.Add("onclick", "RowOnClick('" & DataBinder.Eval(e.Item.DataItem, "judgmentid") & "');")
            e.Item.Cells(0).Text = DateTime.Parse(DataBinder.Eval(e.Item.DataItem, "decision_datetime")).ToShortDateString
            e.Item.Cells(1).Text += " " & DataBinder.Eval(e.Item.DataItem, "casenumber") & " " & DataBinder.Eval(e.Item.DataItem, "year")
            If Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "is_published")) = 0 Then
                e.Item.Cells(6).Text = "N"
                e.Item.Cells(6).ForeColor = Color.Red
            Else
                e.Item.Cells(6).Text = "Y"
            End If

        End If
    End Sub

Which is the sub below it. Any ideas?
 
No it is not automatic. Also, the itemdatabound is fired everytime the page postsback. When you click the delete link button, it causes a post back and that's why the ItemDataBound event fires. Your delete code has to be specified in the HTML as tperri already pointed out.
 
in your dg html you need something like the following

OnUpdateCommand="YourdgUpdateCommand" OnEditCommand="YourdgEditCommand"
OnItemCommand="YourdgInsertCommand"
OnDeleteCommand="YourdgDeleteCommand"

 
OK cheers for that guys I have amended to

Code:
<trans:groupedgrid id="DecisionGrid" runat="server" EnableViewState="False" AutoGenerateColumns="False"
		AllowCustomSorting="True" CssClass="search-results-table percent80" AllowRowHighlighting="True"
		RemoveRedundantBorders="False" ReorganiseItemStyles="True" UseAccessibleHeader="True"
		OnItemCommand="DecisionGrid_ItemDataBound" OnDeleteCommand="DecisionGrid_DeleteCommand">

and am now getting the error

Code:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: BC30408: Method 'Public Sub DecisionGrid_ItemDataBound(source As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)' does not have the same signature as delegate 'Delegate Sub DataGridCommandEventHandler(source As Object, e As System.Web.UI.WebControls.DataGridCommandEventArgs)'.

Have googled the error but cant figure out why its happening!

Any clues guys?

 
ok have fixed that error my code now stands as this.

Code:
<trans:groupedgrid id="DecisionGrid" runat="server" EnableViewState="False" AutoGenerateColumns="False"
		AllowCustomSorting="True" CssClass="search-results-table percent80" AllowRowHighlighting="True"
		RemoveRedundantBorders="False" ReorganiseItemStyles="True" UseAccessibleHeader="True"
		OnDeleteCommand="DecisionGrid_DeleteCommand">
		<Columns>			
			<asp:BoundColumn DataField="decision_datetime" SortExpression="decision_datetime" HeaderText="Date of Hearing"></asp:BoundColumn>
			<asp:BoundColumn DataField="applicant" SortExpression="applicant" HeaderText="Applicant"></asp:BoundColumn>
			<asp:BoundColumn DataField="respondent" SortExpression="respondent" HeaderText="Respondent"></asp:BoundColumn>
			<asp:BoundColumn DataField="title_no" SortExpression="title_no" HeaderText="Title No"></asp:BoundColumn>
			<asp:BoundColumn DataField="category" SortExpression="category" HeaderText="Category"></asp:BoundColumn>
			<asp:BoundColumn DataField="subcategory" SortExpression="subcategory" HeaderText="Subcategory"></asp:BoundColumn>
			<asp:BoundColumn DataField="is_published" SortExpression="is_published" HeaderText="Published"></asp:BoundColumn>			
			<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete">
				<itemstyle HorizontalAlign="Center" />
			</asp:ButtonColumn>
		</Columns>
	</trans:groupedgrid>


Code:
 Protected Sub DecisionGrid_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DecisionGrid.DeleteCommand
        Dim DecIDLabel As Label = e.Item.FindControl("DecIDLabel")
        If Not DecIDLabel Is Nothing Then
            Me.DeleteDecision(DecIDLabel.Text)
        End If
    End Sub


Code:
 Protected Sub DecisionGrid_ItemDataBound(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            e.Item.Attributes.Add("onclick", "RowOnClick('" & DataBinder.Eval(e.Item.DataItem, "judgmentid") & "');")
            e.Item.Cells(0).Text = DateTime.Parse(DataBinder.Eval(e.Item.DataItem, "decision_datetime")).ToShortDateString
            e.Item.Cells(1).Text += " " & DataBinder.Eval(e.Item.DataItem, "casenumber") & " " & DataBinder.Eval(e.Item.DataItem, "year")
            If Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "is_published")) = 0 Then
                e.Item.Cells(6).Text = "N"
                e.Item.Cells(6).ForeColor = Color.Red
            Else
                e.Item.Cells(6).Text = "Y"
            End If
        End If
    End Sub

However NOW none of them are firing. I had to remove "Handles DecisionGrid.ItemDataBound" off the end of the itembound proc because it was erroring and now it compliles but doesnt do anything
 
here is my postback code if it helps

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PagerControl.PageSize = Configuration.GetInt("DCA.TribunalsService.LandsAdjudicator.Web.Search.Grid.PageSize")
        Page.RegisterClientScriptBlock("dropdowns", Me.ClientSideScript)
        Utility.PopulateCommissioners(drpCommissioner, 0)

        If Not IsPostBack Then
            Utility.PopulateCategory(drpCategory)
            PagerControl.PageIndex = 1
        End If

        If IsPostBack Then

            If Not Request.UrlReferrer.AbsolutePath.ToString = Request.Path.ToString Then
                ' have come back from view page
                'Utility.PopulateCategory(drpCategory)
                PagerControl.PageIndex = Request.QueryString("PagerControl_PageIndex")
                'If Not Request("drpCategory").Equals(String.Empty) Then
                '    drpCategory.Items.FindByValue(Request("drpCategory")).Selected = True
                'End If
            End If

            If Not drpCategory.SelectedItem.Value = -1 Then
                Utility.PopulateSubCategory(drpSubcategory, drpCategory.SelectedItem.Value)
                If Not Request("drpSubcategory").Equals(String.Empty) Then
                    drpSubcategory.Items.FindByValue(Request("drpSubcategory").ToString).Selected = True
                End If
            End If
            If Not Request("drpCommissioner").Equals(String.Empty) Then
                drpCommissioner.Items.FindByValue(Request("drpCommissioner").ToString).Selected = True
            End If
        End If

        drpCategory.Attributes.Add("onchange", "populate(this, 'Form1', 'drpSubcategory', this.selectedIndex);")
        btnSearch.Attributes.Add("onclick", "document.forms[0].action = ""default.aspx""")
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top