2017-06-14 23 views
0

レコードを削除するための値を取得する際に問題があります。 私はtemplatefieldsとのGridViewにOnRowDeleting使用している、と私は削除するレコードを選択された値をretriveことができない、これは私のグリッドです:GridViewで行削除の値を取得できません

<asp:GridView ID="gvw_Cli_Emp_EmpData" runat="server" AutoGenerateColumns="false" 
     CssClass="mGrid" PagerStyle-CssClass="pgr" Width="50%" AutoGenerateDeleteButton="True" 
     AlternatingRowStyle-CssClass="alt" Font-Size="Small" OnRowDeleting="Borrando"> 
     <Columns> 
      <asp:TemplateField> 
       <ItemTemplate> 
        <a href="#" onclick="window.open('Clientes_Empleados_Detalle.aspx?cliCod= <%#Eval("ClienteCodigo1").ToString() 
         + "&EmpNom=" + Eval("Empleado1").ToString() 
         + "&EmpCod=" + Eval("IdCliEmp").ToString() 
         + "&idDepart=" + Eval("IdDepartamento").ToString() 
         + "&Depart=" + Eval("Departamento1").ToString() 
         + "&EmpNiv=" + Eval("NivelAcceso1").ToString()  
         %> ','PrintMe','height=500px,width=800px,scrollbars=1');">Editar</a> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="CLIENTE"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_CliCod" runat="server" Text='<%# Eval("ClienteCodigo1") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="CODIGO"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_EmpId" runat="server" Text='<%# Eval("IdCliEmp") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="EMPLEADO"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_EmpNom" runat="server" Text='<%# Eval("Empleado1") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="ID DEP"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_DepId" runat="server" Text='<%# Eval("IdDepartamento") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="DEPARTAMENTO"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_EmpDep" runat="server" Text='<%# Eval("Departamento1") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="NIVEL"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_EmpNiv" runat="server" Text='<%# Eval("NivelAcceso1") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 

     </Columns> 
    </asp:GridView> 

および削除のために:

protected void Borrando(object sender, GridViewDeleteEventArgs e) 
{ 
    string cell = gvw_Cli_Emp_EmpData.Rows[e.RowIndex].Cells[0].Text; //this retuns me "" 
    int EmpCliCod = Convert.ToInt32(cell); 

    DialogResult dialogResult = MessageBox.Show(new Form { TopMost = true }, "Delete?", "Confirma", MessageBoxButtons.YesNo); 
    if (dialogResult == DialogResult.Yes) 
    { 
     cliEmpBL.clientesEmpleados_SupEmpleado(EmpCliCod); //here execute deletion record from my datalayer 
     Page.ClientScript.RegisterStartupScript(this.GetType(), "AlertScript", "alert('Deleted!');", true); 
    } 
    else if (dialogResult == DialogResult.No) 
    { } 
} 

だから、として私を返す ""を見ることができます。 私が使用して、この決意を試してみました:、任意のアイデアを

 System.Windows.Forms.Label EmpId = e.Item.FindControl("lbl_CliEmp_CliCod") as System.Windows.Forms.Label; 
    string val = EmpId.Text; 

しかし、同じ結果? お願いします。誰も私を助けることができたら幸いです。

よろしく

+0

'MessageBox'はasp.netの機能ではありません。それはwinformsのためです。 Web環境で 'System.Windows.Form'を使わないでください。 – VDWWD

答えて

1

例の下に実装してください、あなたはおかげで、あなたのソリューションが私を助けたパトリック選択された行のID

<asp:LinkButton ID="lnkdelete" runat="server" CommandName="Delete" CommandArgument='<%#Eval("ClienteCodigo1")%>'>Delete</asp:LinkButton> 

protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "Delete") 
    { 
     int ID = Convert.ToInt32(e.CommandArgument); 
     //now perform the delete operation using ID value 
    } 
} 
0

取得します。

<asp:GridView ID="gvw_CliEmp_EmpData" runat="server" AutoGenerateColumns="false" 
     CssClass="mGrid" PagerStyle-CssClass="pgr" Width="50%" 
     AlternatingRowStyle-CssClass="alt" Font-Size="Small" 
     OnRowCommand="gvw_CliEmp_EmpData_RowCommand" OnRowDeleting="gvw_CliEmp_EmpData_RowDeleting"> 
     <Columns> 
      <asp:TemplateField> 
       <ItemTemplate> 
        <a href="#" onclick="window.open('Clientes_Empleados_Detalle.aspx?cliCod= <%#Eval("ClienteCodigo1").ToString() 
         + "&EmpNom=" + Eval("Empleado1").ToString() 
         + "&EmpCod=" + Eval("IdCliEmp").ToString() 
         + "&idDepart=" + Eval("IdDepartamento").ToString() 
         + "&Depart=" + Eval("Departamento1").ToString() 
         + "&EmpNiv=" + Eval("NivelAcceso1").ToString()  
         %> ','PrintMe','height=500px,width=800px,scrollbars=1');">Editar</a> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="CLIENTE"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_CliCod" runat="server" Text='<%# Eval("ClienteCodigo1") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="CODIGO"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_EmpId" runat="server" Text='<%# Eval("IdCliEmp") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="EMPLEADO"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_EmpNom" runat="server" Text='<%# Eval("Empleado1") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="ID DEP"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_DepId" runat="server" Text='<%# Eval("IdDepartamento") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="DEPARTAMENTO"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_EmpDep" runat="server" Text='<%# Eval("Departamento1") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="NIVEL"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_CliEmp_EmpNiv" runat="server" Text='<%# Eval("NivelAcceso1") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField> 
       <ItemTemplate> 
        <asp:LinkButton ID="lnkdelete" runat="server" CommandName="Delete" 
         CommandArgument='<%#Eval("IdCliEmp")%>'>Eliminar 
        </asp:LinkButton> 
       </ItemTemplate> 
      </asp:TemplateField> 


     </Columns> 
    </asp:GridView> 

と背後にあるコード:

#region ==== BORRAR REGISTROS DEL INGRESO ==== 

protected void gvw_CliEmp_EmpData_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "Delete") 
    { 
     int EmpCliCod = Convert.ToInt32(e.CommandArgument); 

     DialogResult dialogResult = MessageBox.Show(new Form { TopMost = true }, "Eliminar?", "Confirmar", MessageBoxButtons.YesNo); 
     if (dialogResult == DialogResult.Yes) 
     { 
      cliEmpBL.clientesEmpleados_SupEmpleado(EmpCliCod); //eliminar desde DL 
      Page.ClientScript.RegisterStartupScript(this.GetType(), "AlertScript", "alert('Eliminado!');", true); 
     } 
     else if (dialogResult == DialogResult.No) 
     { } 

     gvw_CliEmp_EmpData.DataSource = null; 
     gvw_CliEmp_EmpData.DataBind(); 
     gvw_CliEmp_EmpData.DataSource = cliEmpBL.clientes_Empleados_cons_EmpxCliente(lbl_CliEmp_CliCod.Text); 
     gvw_CliEmp_EmpData.DataBind(); 
    } 


} 

protected void gvw_CliEmp_EmpData_RowDeleting(object sender, GridViewDeleteEventArgs e) 
{//this is because grid fired event RowDeleting which wasn't handled 
} 
#endregion 
+0

あなたは歓迎です:) –

関連する問題