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 8994791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:30:29+00:00 2026-06-15T23:30:29+00:00

I have this table in a gridview. ID Question_No Question Survey_ID ———————————————————– 1 1

  • 0

I have this table in a gridview.

ID     Question_No          Question             Survey_ID
-----------------------------------------------------------

 1         1            Whats you name?             44
 2         2            How Old Are you?            44
 3         3       Whats your favorite hobby        44
 4         4          What did you study?           44 

I want to add a remove button to the page that works like this: When i delete one of these records, i want to update the question_no of all the questions automatically as long as the survey_ID is 44. For example, If i delete the 2nd question, it would become like this.

    ID     Question_No          Question             Survey_ID
-----------------------------------------------------------

     1         1            Whats you name?             44
     3         2       Whats your favorite hobby        44
     4         3          What did you study?           44 

How do i do this? i figured it must be a loop, but i have no idea how to even approach it.

EDIT: This is my remove button code

protected void RemoveQuestionButton_Click(object sender, EventArgs e)
        {
            try
            {
                DataRowView r;
                r = ((DataRowView)QuestionsGridView.GetRow(QuestionsGridView.FocusedRowIndex));
                Session["Question_ID"] = r[0];

                if (Session["Question_ID"] != null)
                {
                    SqlConnection connection = DatabaseConnection.GetSurveySystemConnection();
                    string delStatement1 = "DELETE FROM Questions WHERE ID =" + Session["Question_ID"];
                    string delStatement2 = "DELETE FROM Question_Options where Question_ID=" + Session["Question_ID"];
                    SqlCommand cmd = new SqlCommand(delStatement1, connection);
                    SqlCommand cmd2 = new SqlCommand(delStatement2, connection);
                    cmd.CommandType = CommandType.Text;
                    cmd2.CommandType = CommandType.Text;

                    try
                    {
                        cmd2.ExecuteNonQuery();
                        cmd.ExecuteNonQuery();
                        ConfirmLbl.ForeColor = System.Drawing.ColorTranslator.FromHtml("Green");
                        ConfirmLbl.Text = "Question & Options Deleted Successfully!";
                        QuestionsGridView.DataBind();

                    }
                    catch (Exception)
                    {
                        ConfirmLbl.ForeColor = System.Drawing.ColorTranslator.FromHtml("red");
                        ConfirmLbl.Text = "This Question Has Options Linked to it...";
                    }
                    finally
                    {
                        connection.Close();

                    }
                }
            }
            catch (Exception)
            {
                ConfirmLbl.ForeColor = System.Drawing.ColorTranslator.FromHtml("red");
                ConfirmLbl.Text = "You need to select a Question to edit...";
            }
        }
  • 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-06-15T23:30:29+00:00Added an answer on June 15, 2026 at 11:30 pm

    This can be done with a single update statement.

    delete from question
       where id = 2;
    
    with new_order as (
       select row_number() over (partition by survey_id order by question_no) as new_question_no,
              question_no as old_question_no, 
              id
       from question
    ) 
    update question 
      set question_no = nq.new_question_no
    from new_order nq
    where nq.id = question.id
      and survey_id = 44;
    
    commit;
    

    Here is an SQLFiddle example: http://sqlfiddle.com/#!6/0a1e7/1

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

Sidebar

Related Questions

i have a gridview table like this... <div> <asp:GridView ID=GridView1 runat=server AllowSorting=true OnSorting=TaskGridView_Sorting >
Hey guys, I have a question about asp.net I have this table with checkbox
I have this table I created manually, and I want to use a gridview
I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have this table: UNIQUE_ID | WINNER_ID | FINALIST_ID ________1 | ________1 | __________2
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have this table [Table 1] cid | arrived | date_arrived The [arrived field
I have this table, which can be seen as a basic custom gantt chart:
I have this table And my goals is to have a table looking like
I have this table ---------------- | X | Y | ---------------- | a |

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.