Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here I created a grideview containging joblist.below that i added one datadetailview .when anybody select the row in gridview it will shown in detail view...I added one column checkbox in the detailview.when anbody select the checkbox and click apply button below ,the data in the detailview must be added to another table applied jobs.how can we do that?
Posted
v2
Comments
Vinodh.B 26-Dec-13 5:18am    
Where you are facing the problem ? design or coding . If coding means what had you tried and try to paste the code .

1 solution

On Apply Button Click Event, do the following things.

  • Initialize a new DataTable
  • Loop through the DetailsView Items/Rows. Inside the loop...

    • Get the CheckBox Control by FindControl or something
    • Determine if it is Checked or not by CheckBox.Checked Property[^]
    • If that is checked add that Row to the new DataTable initialized before the loop

  • Now do anything you want to do with the new DataTable
 
Share this answer
 
v3
Comments
Member 10467514 26-Dec-13 5:46am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class joblist : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("CompanyName"), new DataColumn("Designation") });
dt.Rows.Add("NIIT", "programmer");
dt.Rows.Add("annvision", "Webdesigner");
dt.Rows.Add("softtech", "designer");
dt.Rows.Add("Mahad", "Programmer");
DetailsView1.DataSource = dt;
DetailsView1.DataBind();
}

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("~/secure.aspx");
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (GridView1.SelectedRow == null)
{
DetailsView1.Visible = false;
}
else
{
DetailsView1.Visible = true;
}
}

protected void Apply_Click(object sender, EventArgs e)
{
Response.Write("You are successfully applied");

DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("CompanyName"), new DataColumn("Designation") });
foreach (DetailsViewRow row in DetailsView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
if (chkRow.Checked)
{
string CompanyName = row.Cells[1].Text;
string Designation = (row.Cells[2].FindControl("lblDesignation") as Label).Text;
dt.Rows.Add(CompanyName, Designation);
}
}
}
GridView2.DataSource = dt;
GridView2.DataBind();

}


}
it showing error near detailview1.DataBind();
What is that Error?
Member 10467514 26-Dec-13 5:55am    
Invalid OperationException was unhandled by usercode
Both DataSource and DataSourceID are defined on 'DetailsView1'. Remove one definition.
Where have you declared DataSourceID of DetailsView?
Member 10467514 26-Dec-13 6:18am    
in the above code

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