You have to get the Employees to which the work has not been assigned in main page.
and on other page get the employees which have work assigned.
First Page HTML:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Assigned">
<ItemTemplate>
<asp:DropDownList ID="ddlWork" runat="server">
<asp:ListItem Text="Developer" Value="0"></asp:ListItem>
<asp:ListItem Text="Designer" Value="1"></asp:ListItem>
<asp:ListItem Text="Database Designer" Value="2"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assigned">
<ItemTemplate>
<asp:CheckBox ID="chkWorkAssign" runat="server" Checked='<%# Eval("checked") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" Text="Assign" OnClick="AssignWork" runat="server" />
</div>
</form>
First Page C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Populate();
}
}
private void Populate()
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection _cn = new SqlConnection(constr))
{
using (SqlCommand _cmd = new SqlCommand("SELECT * FROM WorkAssignment Where checked = 0", _cn))
{
using (SqlDataAdapter da = new SqlDataAdapter(_cmd))
{
_cn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
_cn.Close();
}
}
}
}
protected void AssignWork(object sender, EventArgs e)
{
int id;
string work;
foreach (GridViewRow row in this.GridView1.Rows)
{
if ((row.Cells[3].FindControl("chkWorkAssign") as CheckBox).Checked == true)
{
id = Convert.ToInt32(row.Cells[0].Text);
work = (row.Cells[2].FindControl("ddlWork") as DropDownList).SelectedItem.Text;
this.Update(id, work);
}
}
Response.Redirect("Page2.aspx");
}
private void Update(int id, string work)
{
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
string sqlStatment = "UPDATE WorkAssignment SET WORK = @Work, checked = @checked WHERE Id = @id";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sqlStatment, con))
{
con.Open();
cmd.Parameters.AddWithValue("@Id", id);
cmd.Parameters.AddWithValue("@Work", work);
cmd.Parameters.AddWithValue("@checked", 1);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Second Page HTML:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Work" HeaderText="Assigned Work" />
</Columns>
</asp:GridView>
</div>
</form>
C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Populate();
}
}
private void Populate()
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection _cn = new SqlConnection(constr))
{
using (SqlCommand _cmd = new SqlCommand("SELECT * FROM WorkAssignment Where checked = 1", _cn))
{
using (SqlDataAdapter da = new SqlDataAdapter(_cmd))
{
_cn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
_cn.Close();
}
}
}
}
SQL:
CREATE TABLE [dbo].[WorkAssignment](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) NOT NULL,
[Work] [varchar](50) NOT NULL,
[checked] [bit] NULL,
CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Thank You.