Create Dynamic Table on Selected CheckBox of a GridView

Monday, June 25, 2012

#region " Declare All "
    DataTable dtPrint = new DataTable();                                   // Create Table object
    Int32 no=1;
    Int32 i = 0;  

   DataColumn dc1=new DataColumn("sl",typeof(int));         //declare Column
   DataColumn dc2=new DataColumn("tr",typeof(string));
   dtPrint.Columns.Add(dc1);                                              // Add Column to tha Table
   dtPrint.Columns.Add(dc2);
   DataRow dr;                                                                   // Create dataRow Object

#endregion

# region " In the Event like- Button Click"

        foreach (GridViewRow gvr in grdUnPrinted.Rows)
        {
            CheckBox ckb=(CheckBox)gvr.FindControl("CheckBox1");
            if (ckb.Checked == true)
            {
           

                Label lbltrno=(Label)gvr.FindControl("lblTrNo");
                string trno=lbltrno.Text;

                dr = dtPrint.NewRow();
                dtPrint.Rows.Add(dr);

                //for(int i=0;i<10;i++)
                //{

                    dtPrint.Rows[i]["sl"] = no;
                    dtPrint.Rows[i]["tr"] = trno;
                    i++;

                //}
                    no++;
            }
        }
#endregion

0 comments:

Post a Comment