0

I'm using c# and I have two buttons inside gridview to accept and reject.

If the admin clicks on accept button, it will display confirmation message.

If the admin clicks 'OK' it will change the request status in database and I want to refresh the gridview after click 'OK' to disable accepted student.

This is my code but it is not working

This confirmation message to display 'Ok' or 'cancel' by using java script

function ConfirmAccept() {
        var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";

   if (confirm("Are you sure Accept?")) {
       confirm_value.value = "OK";
       //history.go(0);
       //window.location.href = window.location.href;
       //location.reload(true);
        } else {
            confirm_value.value = "Cancle";
   }

   document.forms[0].appendChild(confirm_value);

    }

and this button is inside gridview

<asp:TemplateField HeaderText="Request Status">
            <ItemTemplate>
                <asp:Button ID="Accept" runat="server" CommandName="Accept" Text="Accept" OnClick="RequestStatus" OnClientClick="ConfirmAccept()"  />
                <asp:Button ID="Reject" runat="server" CommandName="Reject" Text="Reject" OnClick="RequestStatus" OnClientClick="ConfirmReject()" />

            </ItemTemplate>
        </asp:TemplateField>

and this request status in c#

protected void RequestStatus(object sender, System.EventArgs e)
{

    //Get the button that raised the event
    Button btn = (Button)sender;

    //Get the row that contains this button
    GridViewRow row = (GridViewRow)btn.NamingContainer;

    //Get the national Id of the row 
    String nationalID = row.Cells[4].Text;

    //get the id of the button user clicked
    string buttonId = btn.ID;

    string confirmValue = Request.Form["confirm_value"];

    String RowRequestStatus;

    if (buttonId == "Accept"  )
    {

        if (confirmValue == "OK")
        {
           // TextBox1.Text = "accept";
            // this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You sure accept " + row.Cells[4].Text + "!')", true);
            RowRequestStatus = "Accept";

            getdataobj.changeRequestStatue(RowRequestStatus, nationalID);
            btn.PostBackUrl = "~/Admin.aspx";
        }
    }
    else if (buttonId == "Reject")
    {
        if (confirmValue == "OK")
        {
            // this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You sure Reject " + row.Cells[4].Text + " !')", true);

            RowRequestStatus = "Reject";

            getdataobj.changeRequestStatue(RowRequestStatus, nationalID);

        }
    }



}
2
  • Which part is not working & what you're expect? Explain further to get some insights. Commented Aug 9, 2017 at 9:11
  • When i click the OK message the row should removed from grid view but it is not working except if i refresh the page Commented Aug 9, 2017 at 12:07

1 Answer 1

2

You could check request status from database before you load your grid view. for example:

 var details = (from st in db.Students
                               join reg in db.Registrations on st.StudentId equals reg.StudentId
                               where (reg.Status== 0)
                               select new
                               {
                                   Name=/.../
                                   Address = /.../ }

and then load it to your gridview.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.