Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6671951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:27:04+00:00 2026-05-26T03:27:04+00:00

I’ve got my code to delete rows out of the database when the user

  • 0

I’ve got my code to delete rows out of the database when the user clicks on the Delete button in my GridView, but the GridView isn’t updating to reflect the new data changes.

Here’s my code:

    <asp:GridView runat="server" ID="grdQuestions" AutoGenerateColumns="false" Width="100%" CellSpacing="10"
         PagerSettings-Visible="true">
        <HeaderStyle CssClass="aspNetHeader" />
        <Columns>
            <asp:BoundField DataField="QuestionID" HeaderText="QID" />
            <asp:BoundField DataField="ModuleID" HeaderText="Mod #" />
            <asp:BoundField DataField="QuestionText" HeaderText="Question" />
            <asp:BoundField DataField="CorrectAnswer" HeaderText="Answer" />
            <asp:BoundField DataField="AnswerNote" HeaderText="Note" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:HyperLink runat="server" ID="lnkEdit" Text="Edit"></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton runat="server" ID="lnkDelete" Text="Delete" CommandArgument='<%# eval("QuestionID") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

Protected Sub grdQuestions_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdQuestions.RowCommand
    If e.CommandName = "Delete" Then

        sql = "delete from tmp_Questions where QuestionID = " & e.CommandArgument
        Dim cmd As New SqlCommand(sql, d.SQLConnection)

        d.SQLConnection.Open()
        cmd.ExecuteNonQuery()
        d.SQLConnection.Close()

        GetModuleData()
    End If
End Sub

Protected Sub grdQuestions_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles grdQuestions.RowDeleting
    GetModuleData()
End Sub

Private Sub GetModuleData()
    ' ddlModules is a drop down where the user can select a module to filter questions by.
    Dim selid As Integer = ddlModules.SelectedItem.Value
    sql = "select QuestionID, ModuleID, LEFT(QuestionText, charindex(' ', QuestionText, 30)) as QuestionText, CorrectAnswer," & vbCrLf & _
        "AnswerNote from tmp_Questions" & vbCrLf & _
        "where ModuleID = " & selid & vbCrLf & _
        "order by ModuleID"
    Dim cmd As New SqlCommand(sql, d.SQLConnection)
    cmd.CommandText = sql

    QuestionAdapter.SelectCommand = cmd
    QuestionAdapter.Fill(QuestionData)

    If QuestionData.Tables(0).Rows.Count > 0 Then

        grdQuestions.DataSource = QuestionData
        grdQuestions.DataBind()
    End If
End Sub

Thanks in advance for having a look!

EDIT 1:
Did some stepping through the code and found that e.CommandArgument is not getting a value in grdQuestions_RowCommand

EDIT 1 (Revised):
The fact that e.CommandArgument wasn’t getting a value was my mistake. I’d changed the way it’s value was being assigned without removing the previous method.
The code runs through grdQuestions_RowCommand and then goes into grdQuestions_RowDeleting and then executes GetModuleData.
I have a feeling that to view changes to the grid, a PostBack might be required, but I’ve removed all DataBinding to an If Not IsPostBack Then block because the alternative caused problems with the DropDownList whose selection is used as a reference to populate the grid (ddlModules selected the Module whose Questions will display in the grid).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:27:05+00:00Added an answer on May 26, 2026 at 3:27 am

    You have neither specified the CommandName="Edit" for lnkEdit nor CommandName="Delete" for lnkDelete.

    I have a feeling that to view changes to the grid, a PostBack might be required

    Of course, a postback must occur and the GridView must be databound to it’s DataSource again after you’ve deleted the record. But that postback has been already occured when the user clicked the delete-link and the grdQuestions_RowDeleting has been handled.
    Debug and ensure that the record gets deleted and afterwards the GridView gets databound again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i got an object with contents of html markup in it, for example: string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.