Click here to Skip to main content
15,904,497 members

Select Values from a dataset into anothr dataset

Latest Revision
Hi all,
I have a dataset which binds data to the Gridview in my page. I have check boxes to it. Whe i click a button in my page i need to bind the selected rows in my gridview into another dataset or into another datatable.pls help how to do it.. i have attached my code with this...

pls help with necessary changes in my code...
C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           fillgrid();
       }
   }

   protected void btnPdfReport_Click(object sender, EventArgs e)
   {
        GetEmpID();
   }


   public void fillgrid()
   {
       string connString = "Data Source=xxxx\\sqlexpress;Initial Catalog=ISSUsers;User=sa;Password=123456;Integrated Security=false";
       string sqlQuery = "SELECT Employee_ID,Employee_Name,Employee_Country,Age,Contact_Number,Employee_Mail,DateOfJoining,Department_ID,Manager,Salary FROM Employees  ORDER BY Employee_Country";   //where Employee_ID=100
       getResultSet(connString, sqlQuery);
       gridISSControl.DataSource = dsResultTable;
       gridISSControl.DataBind();
    }

   public DataSet getResultSet(string connectionString, string sqlSentence) //Get dataset for Grid
   {
       try
       {
           string connString = connectionString;
           string sqlQuery = sqlSentence;
           dsResultTable = new DataSet();
           dt = new DataTable();
           SqlCommand SqlCmdObject = new SqlCommand(sqlQuery, SqlConObject);
           SqlDataAdapter da = new SqlDataAdapter(SqlCmdObject);
           da.Fill(dsResultTable);
       }
       catch (Exception e)
       {
           lblError.Text = e.Message;
       }
       finally
       {
           SqlConObject.Close();
       }
       return dsResultTable;
   }

  public void CreateDatatableofSelectedRows() //Get Employee ID's
   {
       ArrayList names = new ArrayList();
       foreach (GridViewRow gvr in this.gridISSControl.Rows)
       {
           if (((System.Web.UI.WebControls.CheckBox)gvr.FindControl("chkSelect")).Checked == true)
           {
               names.Add(gvr.Cells[1].Text);
           }
       }

       this.lblError.Text = string.Empty;
       foreach (object itm in names)
       {
           //Create another  datatable here if possible..!!!!
       }
     }



I need to Select the records which the user has selected via the textbox into a datatable or a dataset.Pls help it...
Posted 5-Oct-12 0:42am by ajithk444.