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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:22:04+00:00 2026-06-07T00:22:04+00:00

I am a new ASP.NET developer and I am developing a web-based suggestions box

  • 0

I am a new ASP.NET developer and I am developing a web-based suggestions box program for my company where the employees can submit any safety suggestions they have. Now, I am working on the Administration part of this system.

The Admin will be able to see all suggestions listed in a GridView control. In the last column of the GridView, the status will be listed there. When the Admin clicks on the status of one of these suggestion, a new pop-up window (asp.net ajax ModalPopUpExtender) will be appeared with listing all the possible status such as: actioned, approved… etc. And when the Admin selects one of these status, the status of the suggestion will be updated in the database. I wrote the code but still it doesn’t update the status of the suggestion,

so could you please help me in modifying it?

FYI, I have the following database design:

Employee Table: Username, Name...
SafetySuggestionsLog: ID, Title, Description, Username, StatusID
SafetySuggestionsStatus: ID, Status

ASP.NET code:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" 
                        width="900px" CssClass="mGrid" 
                        DataSourceID="SqlDataSource1" 
                        OnRowDataBound="GridView1_RowDataBound">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" CssClass="alt" />
            <HeaderStyle Font-Bold = "True" ForeColor="Black" Height="20px"/> 
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    SortExpression="Description" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Username" HeaderText="Username" 
                    SortExpression="Username" />
                <asp:BoundField DataField="DivisionShortcut" HeaderText="DivisionShortcut" 
                    SortExpression="DivisionShortcut" />
                <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />

                <%-- This to make status be opened and edited through the Ajax ModalPopUp Window --%>
                <asp:TemplateField HeaderText="Status">
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lnkSuggestionStatus" Text='<%#Eval("Status")%>'
                                        OnClick="lnkSuggestionStatus_Click">
                        </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>

                <%--<asp:HyperLinkField HeaderText="Status" 
                    SortExpression="Status" />--%>
            </Columns>
            <RowStyle HorizontalAlign="Center" />
        </asp:GridView>

        <asp:Button runat="server" ID="btnModalPopUp" style="display:none" />

        <AjaxToolkit:ModalPopUpExtender ID="modalPopUpExtender1"
                                        runat="server" 
                                        TargetControlID="btnModalPopUp" 
                                        PopupControlID="pnlPopUp" 
                                        BackgroundCssClass="popUpStyle"
                                        PopupDragHandleControlID="panelDragHandle" 
                                        OkControlID="OKButton">
        </AjaxToolkit:ModalPopUpExtender>

        <asp:Panel runat="server" ID="pnlPopUp">

                    <asp:RadioButtonList ID="StatusList" runat="server" RepeatColumns="1" RepeatDirection="Vertical"
                                            RepeatLayout="Table" TextAlign="Left" DataSourceID="SuggestionStatusDataSource"
                                            DataTextField="Status" DataValueField="ID">
                        <asp:ListItem id="option1" runat="server" Value="ACTIONED" />
                        <asp:ListItem id="option2" runat="server" Value="APPROVED" />
                        <asp:ListItem id="option3" runat="server" Value="PENDING" />
                        <asp:ListItem id="option4" runat="server" Value="TRANSFERRED" />
                    </asp:RadioButtonList>
                    <asp:SqlDataSource ID="SuggestionStatusDataSource" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                                        SelectCommand="SELECT * FROM [SafetySuggestionsStatus]"></asp:SqlDataSource>

                    <asp:Button ID="confirmButton" runat="server" Text="Confirm" 
                                OnClientClick="javascript:return confirm('Are you sure you want to send an email notification about the safety suggestion to the owner?')" 
                                OnClick="btnSendStatus_Click" />

            <asp:Button ID="OKButton" runat="server" Text="Close" />
        </asp:Panel>
        </ContentTemplate>
        </asp:UpdatePanel>

Code-Behind:

protected void lnkSuggestionStatus_Click(object sender, EventArgs e)
    {
        LinkButton lnkSuggestionStatus = sender as LinkButton;

//var safetySuggestionsId=

        //get reference to the row selected 
        GridViewRow gvrow = (GridViewRow)lnkSuggestionStatus.NamingContainer;


        //set the selected index to the selected row so that the selected row will be highlighted
        GridView1.SelectedIndex = gvrow.RowIndex;

        //show the modalPopUp
        modalPopUpExtender1.Show();
    }

public void btnSendStatus_Click(object sender, EventArgs e) {
        var statusID = StatusList.SelectedValue;

        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";
        //For updating the status of the safety suggestion
        string updateCommand = "UPDATE SafetySuggestionsStatus SET ID= @statusID where ID=@SafetySuggestionsID"";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            //using (SqlCommand cmd = new SqlCommand(cmdText, conn))
            using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
            {

                cmd.Parameters.AddWithValue("@ID", statusID);
                cmd.ExecuteNonQuery();
            }
        }

        SendSuggestionStatusToUser(statusID);
    }

UPDATE:

When I debugged the code, I got the following error:

SqlException was unhandled by user code 
 Must declare the scalar variable "@SafetySuggestionsID"

UPDATE 2:

I modified my code as you suggested:

protected void lnkSuggestionStatus_Click(object sender, EventArgs e)
    {
        LinkButton lnkSuggestionStatus = sender as LinkButton;

        //var safetySuggestionsId = 

        //get reference to the row selected 
        GridViewRow gvrow = (GridViewRow)lnkSuggestionStatus.NamingContainer;

        //set the selected index to the selected row so that the selected row will be highlighted
        GridView1.SelectedIndex = gvrow.RowIndex;

        HiddenField1.Value = gvrow.RowIndex.ToString();

        //show the modalPopUp
        modalPopUpExtender1.Show();
    }

    public void btnSendStatus_Click(object sender, EventArgs e) {

        var statusID = StatusList.SelectedValue;

        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";
        //For updating the status of the safety suggestion
        string updateCommand = "UPDATE SafetySuggestionsLog SET StatusID= @statusID where ID=@SafetySuggestionsID";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
            {
                cmd.Parameters.AddWithValue("@ID", Convert.ToInt32(statusID));
                cmd.Parameters.AddWithValue("@SafetySuggestionsID", Convert.ToInt32(HiddenField1.Value));
                cmd.ExecuteNonQuery();
            }
            //reset the value of hiddenfield
            HiddenField1.Value = "-1";
        }

        //SendSuggestionStatusToUser(statusID);
    }

However, while I am debugging the code, I got the following error:

Must declare the scalar variable”@statusID”

I don’t know why I am getting this error while I am already defined it.

UPDATE 3:

I added GridView1.DataBind() to update the GridView with the updated status of the selected suggestion but it does not work with me.

public void btnSendStatus_Click(object sender, EventArgs e) {

        var statusID = StatusList.SelectedValue;

        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";
        //For updating the status of the safety suggestion
        string updateCommand = "UPDATE SafetySuggestionsLog SET StatusID= @statusID where ID=@SafetySuggestionsID";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
            {
                cmd.Parameters.AddWithValue("@statusID", Convert.ToInt32(statusID));
                cmd.Parameters.AddWithValue("@SafetySuggestionsID", Convert.ToInt32(HiddenField1.Value));
                cmd.ExecuteNonQuery();
            }
            //reset the value of hiddenfield
            HiddenField1.Value = "-1";
        }

        GridView1.DataBind();

        //SendSuggestionStatusToUser(statusID);
    }

UPDATE 4:
I added the following but it did not work:

public void btnSendStatus_Click(object sender, EventArgs e) {

        var statusID = StatusList.SelectedValue;

        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";
        //For updating the status of the safety suggestion
        string updateCommand = "UPDATE SafetySuggestionsLog SET StatusID= @statusID where ID=@SafetySuggestionsID";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
            {
                cmd.Parameters.AddWithValue("@statusID", Convert.ToInt32(statusID));
                cmd.Parameters.AddWithValue("@SafetySuggestionsID", Convert.ToInt32(HiddenField1.Value));
                cmd.ExecuteNonQuery();
            }
            //reset the value of hiddenfield
            HiddenField1.Value = "-1";
        }

        UpdatePanel1.Update();
        GridView1.DataBind();


        //SendSuggestionStatusToUser(statusID);
    }
  • 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-07T00:22:05+00:00Added an answer on June 7, 2026 at 12:22 am

    I dont see SafetySuggestionsID defined anywhere…u have defined it as statusID

    also when you are adding parameters, you are referring ID…please make these corrections or update the code in your query.

    string updateCommand = "UPDATE SafetySuggestionsStatus SET ID= @statusID";  // where??
            using (SqlConnection conn = new SqlConnection(connString))  
            {  
                conn.Open();  
                //using (SqlCommand cmd = new SqlCommand(cmdText, conn))  
                using (SqlCommand cmd = new SqlCommand(updateCommand, conn))  
                {  
    
                    cmd.Parameters.AddWithValue("@statusID", statusID);  
                    cmd.ExecuteNonQuery();  
                }  
            }  
    

    Update:

    "UPDATE SafetySuggestionsStatus SET ID= @statusID where ID=@SafetySuggestionsID"";
    

    you have defined 2 parameters, but you are adding just 1 in your parameter colleciton:

    cmd.Parameters.AddWithValue("@ID", statusID); // id should be statusID
    // also add @SafetySuggestionsID
    

    Update 2:
    in your lnkSuggestionStatus_Click event handler, get the value of the first column (ID) and store it in a class variable say safetySuggestionsId.

    Then in your btnSendStatus_Click event handler, you can simply add:

    using (SqlConnection conn = new SqlConnection(connString))   
            {   
                conn.Open();   
                //using (SqlCommand cmd = new SqlCommand(cmdText, conn))   
                using (SqlCommand cmd = new SqlCommand(updateCommand, conn))   
                {   
    
                    cmd.Parameters.AddWithValue("@statusID ", statusID); 
                    cmd.Parameters.AddWithValue("@SafetySuggestionsID", safetySuggestionsId);   
                    cmd.ExecuteNonQuery();   
                }   
            } 
    

    Update 3:
    Hope the following works as this is untested…:

    1. add a hidden field in your modal popup panel –>

    2. then in your lnkSuggestionStatus_Click event handler, add:

      hiddenRowIndex.Value = row.Cells[1].Text; // trim if necessary

    3. then when you save, in your btnSendStatus_Click event handler, you can simply add:

             ...
             ...   
              {   
      
                  cmd.Parameters.AddWithValue("@statusID ", statusID); 
                  cmd.Parameters.AddWithValue("@SafetySuggestionsID", 
                                              Convert.ToInt32(hiddenRowIndex.Value));   
                  cmd.ExecuteNonQuery();   
              } 
              // reset hiddenRowIndex
              hiddenRowIndex.Value = "-1";
          } 
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a new ASP.NET website using Visual Web Developer 2008 Express edition and
I'm developing a web application using asp.net. There is a text box which contains
Using ASP.Net Am New to website development Currently am developing a web pages, when
I am developing an asp.net web services. I am new to asp.net but I
In Visual Web Developer Express 2010 I created a default new ASP.NET Webapplication project.
From the developer preview What’s New for ASP.NET 4.5 and Web Development it seems
Windows 7, visual web developer express 2010, c#, asp.net, webforms. Running program with ctrl-F5
I'm developer moving from C# to Java. Heard about new ASP net feature. <%:
New ASP.NET Web API HttpClient has been giving me some strange results. Here is
I am building a new asp.net MVC3 web application for reporting and I want

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.