Click here to Skip to main content
16,003,873 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
See more:
Hi to all,
I want code for chekboxes selected values stored only in gridview not in database.While i click another button it will store data from gridview to database code in asp.net c#
Please send code and design.









Thanks in advance
Posted

1 solution

from this you pass selected value in gridview..\

private void Checked()
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[0].FindControl("CheckBox1") as CheckBox);
if (row.Cells[1].Text == this.CustomerId)
{
chkRow.Checked = true;
}
}
}
}

protected void GetSelectedRecords(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] { new DataColumn("CustomerID"),
new DataColumn("City"),
new DataColumn("Country"),
new DataColumn("PostalCode") });
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[0].FindControl("CheckBox1") as CheckBox);
if (chkRow.Checked)
{
string customerId = row.Cells[1].Text;
string city = row.Cells[2].Text;
string postalCode = row.Cells[3].Text;
string country = row.Cells[4].Text;
dt.Rows.Add(customerId, city, country, postalCode);
}
}
}

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900