2014-05-16 2 views
0

사용자가 명령 필드에서 삭제 버튼을 클릭하면 창을 표시하고 "조 스미스를 삭제 하시겠습니까?"라는 질문을해야합니다.삭제 확인 팝업 창 팝업 메시지 표시 - GridView ASP.NET

나는 클라이언트 측에서 썼다. 그러나 나는 또한 표시 할 행의 이름이 필요하다.

<asp:CommandField ButtonType="Button" ShowDeleteButton="True" ShowEditButton="True" 
     HeaderText="Action" /> 
    <asp:TemplateField ShowHeader="False"> 
     <ItemTemplate> 
      <asp:Button ID="DeleteButton" runat="server" 
       CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this event?');" 
       AlternateText="Delete" />    
     </ItemTemplate> 

다음은 삭제 행에 대한 코드입니다. 이 방법으로 프롬프트를 코딩 할 수 있습니까? 또는 RowDataBound를 수행해야합니다. 즉 서버 측을 실행하기 때문에

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) 
{ 
    try 
    { 
     string connectionString = System.Configuration.ConfigurationManager.AppSettings["DBConnection"]; 
     SqlConnection connDel = new SqlConnection(connectionString); 

     int User_ID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value); 
     SqlCommand cmd = new SqlCommand("DELETE FROM DoNotPay_Email_List WHERE User_ID=" + User_ID + "", connDel); 
     connDel.Open(); 
     int temp = cmd.ExecuteNonQuery(); 
     /* if (temp == 1) 
     { 
      lblMessage.Text = "Record deleted successfully"; 
     }*/ 
     BindGrid(); 
     cmd.Dispose(); 
     connDel.Close(); 
    } 
    catch (SqlException ex) 
    { 
     lblMessage.Text = (ex.Message); 
    } 
} 


답변

0

당신은 Row_Deleting에 싶지 않아; 그 경로를 간다면 각 삭제 작업마다 여러 개의 포스트 백을 거쳐야합니다.

바운드 행 값에 액세스 할 수있는 RowDataBound 이벤트에서 OnClientClick 속성을 설정해야하며 원하는 데이터를 포함하도록 메시지를 연결할 수 있습니다.

편집 : 3 단계에서 RowDataBound 코드를 살펴보고 단추에 대한 참조를 가져 와서 행 데이터를 검색하고 프롬프트 텍스트를 사용자 지정하는 방법을 보여줍니다.

http://msdn.microsoft.com/en-us/library/bb428868.aspx