Get the row ID of a Gridview query

2

I made a query in which a gridview is populated, the columns are code, category, noprazo, foradoprazo. In the columns in the deadline and foradoprazo, I left them as linkbuttom that when clicking on the resulting item line or late or deadline, I get the ID of the line clicked.

This runs on GridView1_RowCommand as follows, but does not return the id of the clicked row.

What should I do?

   protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Detalhar")
        {

            chamadosEntities carga1 = new chamadosEntities();
            int index = Convert.ToInt32(e.CommandArgument);
            GridView1.SelectedIndex = index;
            int codigoId = Convert.ToInt32(GridView1.DataKeys[index].Value);
    
asked by anonymous 22.10.2015 / 14:15

1 answer

0

See an example below.

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Detalhar")
        {

            chamadosEntities carga1 = new chamadosEntities();
            ButtonCommand Btn = new ButtonCommand(sender);
            int index = Btn.ArgumentAsInt;


            GridView1.SelectedIndex = index;
            int codigoId = Convert.ToInt32(GridView1.DataKeys[index].Value);





   public class ButtonCommand
    {
        private IButtonControl m_Btn = null;

        public ButtonCommand(object sender)
        {
            m_Btn = sender as IButtonControl;
            if (m_Btn == null)
                throw new Exception("sender não é IButtonControl");
        }


        public Int32 ArgumentAsInt
        {
            get
            {
                Int32 Result = 0;
                Int32.TryParse(m_Btn.CommandArgument, out Result);
                return Result;
            }
        }
    }
    
22.10.2015 / 15:10