Wednesday 25 July 2012

How to select values from a datatable based on the condition

// here 'm datatable from cache which is already stored, u can careate ur own datatable  
              
               string district = e.Row.Cells[0].Text.ToString();

                string cachekey = "PPNPreauthDistrictMIS_" + Session.SessionID;
                DataTable NewGdt = (DataTable)HttpRuntime.Cache[cachekey];

                DataRow[] rows = NewGdt.Select("DISTRICT = '" + district + "'");


                 dt = new DataTable();
                dt.Columns.Add("SL No");
                dt.Columns.Add("DISTRICT");
                dt.Columns.Add("PKG_CATEGORY");
                dt.Columns.Add("CASES");
                dt.Columns.Add("AMT");
                dt.Columns.Add("TOTALAPPAMOUNT");

                foreach (DataRow dr in rows)
                {

                    object[] row = dr.ItemArray;

                    dt.Rows.Add(row);

                    casesum = casesum + Convert.ToInt32(dr["CASES"]);
                    pratesum = pratesum + Convert.ToInt32(dr["AMT"]);
                    appamtsum = appamtsum + Convert.ToInt32(dr["TOTALAPPAMOUNT"]);
                }

                DataRow newrow = dt.NewRow();

                newrow["PKG_CATEGORY"] = "Total";
                newrow["CASES"] = casesum.ToString();
                newrow["AMT"] = pratesum.ToString();
                newrow["TOTALAPPAMOUNT"] = appamtsum.ToString();
                dt.Rows.Add(newrow);
                ChildGridview.DataSource = dt;
                ChildGridview.DataBind();
                int count = ChildGridview.Rows.Count;
                ChildGridview.Rows[count - 1].Font.Bold = true;





No comments:

Post a Comment