2017-08-09 83 views
0

我使用C#和我有內部GridView的兩個按鈕來接受和拒絕。更新的GridView在Asp.Net C#

如果管理員點擊了接受按鈕,將顯示確認消息。

如果管理員點擊「確定」它會改變數據庫中的請求狀態,我想後,單擊「確定」關閉接受學生以刷新GridView的。

這是我的代碼,但它不工作

此確認消息顯示「確定」或通過使用Java腳本

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); 

    } 

「取消」,這個按鈕是裏面的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> 

這個請求狀態在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); 

     } 
    } 



} 
+0

哪一部分無法工作和你有什麼期待?進一步解釋以獲得一些見解。 –

+0

當我點擊確定消息的行應該從網格視圖中刪除,但它沒有,除非我刷新頁面 –

回答

2

你可以檢查從數據庫中請求狀態加載網格視圖之前。例如:

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 = /.../ } 

然後將其加載到您的gridview。

+0

謝謝你的工作,我用你的答案和它的工作! –