Access to RowCommand aspx - c #

0

I have a one-to-one table of documents and attachments, when I create a file, I have to attach a file to it

I have these controls

<asp:TemplateField HeaderText="Archivo" HeaderStyle-CssClass="text-center">
       <ItemTemplate>
          <asp:FileUpload ID="fu1" runat="server" />
          <asp:Button ID="btnguardar" runat="server" Text="Adjuntar" CommandName="up" />
      </ItemTemplate>
</asp:TemplateField>

Functionality of the button

protected void gvradica_RowCommand(object sender, GridViewCommandEventArgs e)
{
        Button btnUp = e.CommandSource as Button;
        if (e.CommandName.ToLower() != "up")
        {
            return;
        }
        FileUpload fu = btnUp.FindControl("fu1") as FileUpload;
        if (fu.HasFile)
        {
            DOCADJUNTO da = new DOCADJUNTO();
            if (fu.HasFile)
            {
                da.ID_RADICACION_FK = 1; // El numero 1 es un dato quemado
                da.NOMBRE = System.IO.Path.GetFileNameWithoutExtension(fu.PostedFile.FileName);
                da.EXTENSION = System.IO.Path.GetExtension(fu.PostedFile.FileName);
                da.ARCHIVO = fu.FileBytes;
                adoDocAdj.agregarAdjunto(da);
            }
        }
}

What is wanted is that the ID_RADICACIÓN_FK brings it automatically, from the row of the selected grid, but I have not been able to do it, I have tried to do it in the following ways

int index = Convert.ToInt32(e.CommandArgument);
da.ID_RADICACION_FK = Convert.ToInt32(gvradica.DataKeys[index].Value);

GridViewRow row = gvradica.SelectedRow;
da.ID_RADICACION_FK = Convert.ToInt32(gvradica.DataKeys[row.RowIndex].Value);

GridViewRow row = gvradica.SelectedRow;
da.ID_RADICACION_FK=Convert.ToInt32(gvradica.DataKeys[row.RowIndex].Values["ID_RADICACION"]);

var query = from ra in contexto.RADICACIONES select new { ra.ID_RADICACION };

da.ID_RADICACION_FK = int.Parse(gvradica.SelectedDataKey.Values[0].ToString() + "" + gvradica.SelectedDataKey.Values[1].ToString());

da.ID_RADICACION_FK = Convert.ToInt32(e.CommandArgument);

None is useful

    
asked by Ledferoz10 11.04.2017 в 18:28
source

1 answer

0

To be able to use e.CommandArgument , you must first assign a unique value to each button, in this case the id of the row:

<asp:Button ID="btnguardar" runat="server" Text="Adjuntar" CommandName="up" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>

Then you can already capture it in the RowCommand event:

da.ID_RADICACION_FK = Convert.ToInt32(e.CommandArgument);
    
answered by 11.04.2017 в 20:40