error when passing gridview data to another webform [closed]

0

I'm trying when I click to select in the gridview I show it in another webform to then create a ticket and store it in a database, the gridview is filled through a txt file but when I want to pass the data that I select, it throws me an error cs0246 I think that it does not recognize me the public method that declares it does not recognize it the code where I create the method and the click event of the gridview.

public class datos
{
    public string fecha { get; set; }
    public string nPlanta { get; set; }
    public string mezcla { get; set; }
    public string horaIni { get; set; }
    public string horaFin { get; set; }
    public string peso { get; set; }
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow row = GridView1.SelectedRow;

     datos obj = new datos()
    {
        fecha = row.Cells[0].Text,
        nPlanta = row.Cells[1].Text,
        mezcla = row.Cells[2].Text,
        horaIni = row.Cells[3].Text,
        horaFin = row.Cells[4].Text,
        peso = row.Cells[5].Text
    };

    Session["DataMiClase"] = obj;

    Response.Redirect("ticket.aspx");
}

This is the code where those data that I select should appear to me

protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {
      datos obj = (datos)Session["DataMiClase"];

        if (obj != null)
        {
            lbl1.Text = obj.fecha;
            lbl2.Text = obj.nPlanta;
            lbl3.Text = obj.mezcla;
            lbl4.Text = obj.horaIni;
            lbl5.Text = obj.horaFin;
            lbl6.Text = obj.peso;

        }
    }
}

Error text:

  

Error CS0246 The type or namespace name 'data' could not be found (if you are using a directive or an assembly reference?) production C: \ Users \ jose f leon c \ Documents \ Visual Studio 2015 \ WebSites \ production \ ticket.aspx.cs 16

    
asked by Alexander Villalobos 29.03.2017 в 15:57
source

1 answer

1

From what I see in the code and in the comments, you have a compilation problem by the scope of the class datos from the second form.

It would only be necessary:

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack) return;

    datos obj = Session["DataMiClase"] as webform1.datos;

    if (obj != null)
    {
        lbl1.Text = obj.fecha;
        lbl2.Text = obj.nPlanta;
        lbl3.Text = obj.mezcla;
        lbl4.Text = obj.horaIni;
        lbl5.Text = obj.horaFin;
        lbl6.Text = obj.peso;
    }    
}

Where, webform1 is class of the first form that contains the class datos .

As a recommendation, I suggest you use a better notation , in my humble opinion I use CamelCase.

    
answered by 29.03.2017 в 17:03