0

Hi
I have a list like List<vahed>. this list fill from vahed class.when i want to bind list into gridview ,I store it in Session. but when this list bind to grid view,data is empty.
my code:

//class vahed
public List<Vahed> SelectAll()
        {
            Vahed V = new Vahed();         
            string command = "SELECT FEMAIN.GHAR, VAHED.KARBARINUM, FEMAIN.KOL_AYAN, FEMAIN.KOL_ARSE, FEMAIN.MOFID, FEMAIN.AB_ENSH, FEMAIN.FA_ENSH, FEMAIN.AB_TAFK,FEMAIN.FA_TAFk FROM  FEMAIN INNER JOIN VAHED ON FEMAIN.ID_FEMAIN = VAHED.ID_FEMAIN ";
            SqlCommand sc = new SqlCommand(command, new SqlConnection(GlobalFunction.Function.GetConnectionString()));
            sc.Connection.Open();
            SqlDataReader dr = sc.ExecuteReader();
            List<Vahed> LV = new List<Vahed>();
            using(dr)
            {
                while (dr.Read())
                {
                    V.KARBARINUM=dr["KARBARINUM"].ToString();
                    V.FeObj.Ghar=Convert.ToInt32(dr["GHAR"]);
                    V.FeObj.Kol_Ayan=Convert.ToInt32(dr["KOL_AYAN"]);
                    V.FeObj.Kol_Arse=Convert.ToInt32(dr["KOL_ARSE"]);
                    V.FeObj.Mofid=Convert.ToInt32(dr["MOFID"]);
                    V.FeObj.Ab_Ensh=dr["AB_ENSH"].ToString();
                    V.FeObj.Fa_Ensh=dr["FA_ENSH"].ToString();
                    V.FeObj.Ab_Tafk=dr["AB_TAFK"].ToString();
                    V.FeObj.Fa_Tafk=dr["FA_TAFK"].ToString();
                    LV.Add(V);
                }
            }
            sc.Connection.Close();
            return LV;
        }
// my webpage
        Session["SessFemain"] = v.SelectAll();
        GridFemain.DataSource = (List<BussinessLayer.Vahed>)Session["SessFemain"];      
        GridFemain.AllowPaging = true;
        GridFemain.PageSize = 5;
        GridFemain.DataBind();
2
Contributors
1
Reply
4
Views
10 Years
Discussion Span
Last Post by SheSaidImaPregy
0

for one, don't bind it into a session. Cache the data. Binding it in session is just.. pointless in my opinion. By caching it you will improve performance by far and not have to worry about losing session variables.

Anyway, with your session variable, don't bind it where you are. Bind your data after you close your connection, and try binding it to "Session["SessFemain"] = LV" right before you "return LV;"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.