Shiv
Shiv

Reputation: 77

How do i use Checkboxes in gridview to show data

I Have Two Gridview in first one there is some data with checkbox. I Want when i check two or more checkboxes then show the both record who's checked to another gridview There is my Coding. Problem is it's show only one record at a time..

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)

    {

    foreach(GridViewRow row in GridView1.Rows)

    {

     if (row.RowType == DataControlRowType.DataRow )

      {

       CheckBox chkSelect = (CheckBox)row.Cells[0].FindControl("CheckBox1");

       if (chkSelect != null)

       {

         if (chkSelect.Checked)

         {

           string FoodItem = ((Label)row.FindControl("Label1")).Text.ToString(); 
           string s = "select * from Item where Item_Name='" + FoodItem + "' "; 
           db.grid(s, GridView2);

         }

       }

    }

  }

Upvotes: 0

Views: 986

Answers (1)

Vetrivel mp
Vetrivel mp

Reputation: 1214

By looking your code,

first think dont bind gridview immediately after checking checked property of each check box, it will override gridview2. first collect all check box values by concatinating say FoodItem = "(value1,value2,value3)".

call data base one time by modifying query like

string s = "select * from Item where Item_Name in " + FoodItem +"; 
db.grid(s, GridView2); 

I think you have multiple selection so keep seperate button and write all codes to copy from one grid to another grid inside button click event.

Upvotes: 1

Related Questions