Passing gridview data to a Texbox on asp.net c #

0

Could you help me I want to pass the data from a GRIDVIEW TO A TEXBOX PLEASE. I can not pass the data I would like you to help me.

MY CURRENT CODE IS THIS IS MISTAKE

here:

GridViewRow row = DtgVerGestiones.Rows [0];

 protected void DtgGestiones_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showModal();", true);
            if (e.CommandName == "Gestiones")
            {
                try
                {
                    DtSet = new DataSet();
                    SqlConnection con = new SqlConnection(ObtenerCadenaConexion());
                    con.Open();

                    SqlCommand cmd = new SqlCommand("SP_BuscarSeguimiento", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter p1 = new SqlParameter("OPT", 2);
                    SqlParameter p2 = new SqlParameter("periodo", "");
                    SqlParameter p3 = new SqlParameter("oficina", "");
                    SqlParameter p4 = new SqlParameter("rubro", e.Item.Cells[3].Text);

                    cmd.Parameters.Add(p1);
                    cmd.Parameters.Add(p2);
                    cmd.Parameters.Add(p3);
                    cmd.Parameters.Add(p4);



                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    DtgVerGestiones.DataSource = dt;
                    DtgVerGestiones.Visible = true;
                    DtgVerGestiones.DataBind();

                    GridViewRow row = DtgVerGestiones.Rows[0];

                    TextBox1.Text = Convert.ToString(row.Cells[0].Text);

                    con.Close();






                }
                catch (Exception Ex)
                {
                    // DvError.Visible = true;
                    Session["13"] = Ex.Message;
                }
            }
        }

CODE FROM THE BUTTON SEARCH

protected void btnBuscar_Click(object sender, EventArgs e)
{
    DtgVerGestiones.DataSource = null;
    DtgVerGestiones.DataBind();

    DateTime d3 = DateTime.Parse(dprPeriodo.Text);
    string Periodo = d3.ToString("yyyy-MM-dd");

    SqlConnection con = new SqlConnection(ObtenerCadenaConexion());
    con.Open();

    SqlCommand cmd = new SqlCommand("SP_BuscarSeguimiento", con);
    cmd.CommandType = CommandType.StoredProcedure;
    SqlParameter p1 = new SqlParameter("OPT", 1);
    SqlParameter p2 = new SqlParameter("periodo", Periodo);
    SqlParameter p3 = new SqlParameter("oficina", dprAgencia.Text);
    SqlParameter p4 = new SqlParameter("rubro", DBNull.Value);
    cmd.Parameters.Add(p1);
    cmd.Parameters.Add(p2);
    cmd.Parameters.Add(p3);
    cmd.Parameters.Add(p4);



    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    DtgGestiones.DataSource = dt;
    DtgGestiones.Visible = true;


    DtgGestiones.DataBind();

    con.Close();
}

ERROR:

In other words, this image is what my datagrid generates.

I WANT TO PASS THOSE DATA ON TEXBOX ASI:

    
asked by PieroDev 31.03.2017 в 00:49
source

1 answer

0

Thank you very much I have the solution is to create an event to the datagridview that is RowCommand

if (e.CommandName == "Select")
            {
                try
                {


                    DtSet = new DataSet();

                    SqlConnection con = new SqlConnection(ObtenerCadenaConexion());
                    con.Open();
                    DtgSolicitudes.SelectedIndex = Convert.ToInt32(e.CommandArgument);
                    GridViewRow row = DtgSolicitudes.SelectedRow;
                    SqlCommand cmd = new SqlCommand("SP_BuscarSeguimiento", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter p1 = new SqlParameter("OPT", 2);
                    SqlParameter p2 = new SqlParameter("periodo", "");
                    SqlParameter p3 = new SqlParameter("oficina", "");
                    SqlParameter p4 = new SqlParameter("rubro", row.Cells[3].Text);

                    cmd.Parameters.Add(p1);
                    cmd.Parameters.Add(p2);
                    cmd.Parameters.Add(p3);
                    cmd.Parameters.Add(p4);



                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                   // DtgVerGestiones.DataSource = dt;
                   // DtgVerGestiones.Visible = true;
                   // DtgVerGestiones.DataBind();

                    if (row.Cells[11].Text == "NO")
                    {
                        TextBox1.Attributes.Add("readonly", "readonly");
                        TextBox2.Attributes.Add("readonly", "readonly");
                        TextBox3.Attributes.Add("readonly", "readonly");

                        //TextBox1.Enabled = false;
                        //TextBox2.Enabled = false;
                        //TextBox3.Enabled = false;


                        TextBox1.Text = Convert.ToString(row.Cells[2].Text);
                        TextBox2.Text = Convert.ToString(row.Cells[1].Text);
                        TextBox3.Text = Convert.ToString(row.Cells[3].Text);
                        TextBox4.Text = Convert.ToString(row.Cells[4].Text);
                        TextBox5.Text = Convert.ToString(row.Cells[5].Text);
                        TextBox6.Text = Convert.ToString(row.Cells[6].Text);
                        TextBox7.Text = Convert.ToString(row.Cells[7].Text);
                        TextBox8.Text = Convert.ToString(row.Cells[8].Text);
                        TextBox9.Text = Convert.ToString(row.Cells[9].Text);

                        Image1.ImageUrl = Convert.ToString(row.Cells[12].Text);
                        var imagen = row.FindControl("img") as Image;

                    }
                    else if (row.Cells[11].Text == "SI")
                    {
                        TextBox1.Attributes.Add("readonly", "readonly");
                        TextBox2.Attributes.Add("readonly", "readonly");
                        TextBox3.Attributes.Add("readonly", "readonly");
                        TextBox4.Attributes.Add("readonly", "readonly");
                        TextBox5.Attributes.Add("readonly", "readonly");
                        TextBox6.Attributes.Add("readonly", "readonly");
                        TextBox7.Attributes.Add("readonly", "readonly");
                        TextBox8.Attributes.Add("readonly", "readonly");
                        TextBox9.Attributes.Add("readonly", "readonly");


                        TextBox1.Text = Convert.ToString(row.Cells[2].Text);
                        TextBox2.Text = Convert.ToString(row.Cells[1].Text);
                        TextBox3.Text = Convert.ToString(row.Cells[3].Text);
                        TextBox4.Text = Convert.ToString(row.Cells[4].Text);
                        TextBox5.Text = Convert.ToString(row.Cells[5].Text);
                        TextBox6.Text = Convert.ToString(row.Cells[6].Text);
                        TextBox7.Text = Convert.ToString(row.Cells[7].Text);
                        TextBox8.Text = Convert.ToString(row.Cells[8].Text);
                        TextBox9.Text = Convert.ToString(row.Cells[9].Text);

                        btnActualizar.Visible = false;

                    }

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showModal();", true);
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "VGestiones", "VGestiones()", true);

                    con.Close();



                }
                catch (Exception Ex)
                {
                    // DvError.Visible = true;
                    Session["13"] = Ex.Message;
                }



            }
    
answered by 31.03.2017 / 21:57
source