show checkbox selected rows in a new window asp.net

Posted by Gopal_nivas under ASP.NET on 2/21/2011 | Points: 10 | Views : 10832 | Status : [Member] | Replies : 3
hi ..

i have a gridview in tat i was loaded the table values.

here i cheked 50 rows then i want ot show the 50 selected rows into a new window gridview..

here i dont want to go back again to database after chking the chekbox and store tgose details in temp table...(i want to peroform this in my front end itself)
i am having the values in my grid view so the selected row values are displayed in another page gridview ..

how to do this..
regards
gopal.s




Responses

Posted by: T.saravanan on: 2/21/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Gopal,

Add checkbox in GridView refer this link...http://www.asp.net/data-access/tutorials/adding-a-gridview-column-of-checkboxes-cs
Add a button in your page, In that button click event write the following code for get selected CheckBox value..
protected void btn_Click(....)

{
string sID = string.Empty;
foreach(GridViewRow gvr in GridView1.Rows)
{
CheckBox chk = (CheckBox)gvr.FindControl("chkId"); // Here chkId --> CheckBox Column Id
if(chk.Checked)
{
if(sID != string.Empty)
sID += ",";
sID = sID + GridView1.DataKeys[gvr.RowIndex].Value.ToString();
}
}
DataView dvData = dtGridData.DefaultView; // Here dtGridData --> GridView Data
dvData = string.Format("{0} in ({1})", "nId",sID);
DataTable dtResult = dvData.ToTable();
}

Now you pass the dtResult value into next page to bind the value in gridview.

Try this way.Any more query ask to me..

Cheers :)



Thanks,
T.Saravanan

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shivnaik on: 3/13/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

I have a grid view with dynamic number of columns and I want to update the database based on the selected check boxes. I am unable to find the controls in the code behind using the the check box ID. I am generating the check boxes dynamically in the class file and I am calling that class in code behind.

This is the code to create check box dynamically.

public class TemplateHandler : ITemplate

{
public bool checkSts = false;

public TemplateHandler(bool status)
{
checkSts = status;
}
void ITemplate.InstantiateIn(Control container)
{
CheckBox cBox = new CheckBox();
cBox.Checked = checkSts;
cBox.ID = "chk";
container.Controls.Add(cBox);
}

}


I am calling in code behind like below

  DataTable dt = new DataTable();

dt = FillGridViewDataTable();

//Add the columns to the gridview by creating BoundField dynamically
foreach (DataColumn dColumn in dt.Columns)
{
TemplateField TmpCol = new TemplateField();
TmpCol.HeaderText = dColumn.ColumnName;
TmpCol.ItemTemplate = new TemplateHandler(status);
GridView1.Columns.Add(TmpCol);
}


On update button click event I need to get all the checkbox and check their checked values.

How do I do this?? Please help

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/13/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

You can follow saravanan's code which he mentioned in this thread. Also if the 2nd grid view is available in the same page or you need to redirect to the other page to bind the grdivew? if that is the case then keep the dataset in session or view state to use it in the second page

Thanks
Karthik
www.f5Debug.net

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response