using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblmsg.Visible = false;
}
string conString = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
SqlCommand com;
int check;
protected void EmpDetails(object sender, EventArgs e)
{
DataSet empinfo = new DataSet();
empinfo.ReadXml(Server.MapPath("EmployeeDetails.xml"));
empdetails.DataSource = empinfo;
empdetails.DataBind();
}
protected void SaveRecord(object sender, EventArgs e)
{
for (int i = 0; i <= empdetails.Rows.Count - 1; i++)
{
GridViewRow row = empdetails.Rows[i];
CheckBox Chbox = (CheckBox)row.FindControl("Chkbox");
if (Chbox.Checked == true)
{
check++;
}
}
if (check == 0)
{
Page.RegisterStartupScript("Alert Message",
"<script language='javascript'>alert('Please Check atleast one record');</script>");
return;
}
for (int i = 0; i <= empdetails.Rows.Count - 1; i++)
{
string eid = empdetails.Rows[i].Cells[1].Text;
string uname = empdetails.Rows[i].Cells[2].Text;
GridViewRow gvrow = empdetails.Rows[i];
CheckBox Chbox = (CheckBox)gvrow.FindControl("Chkbox");
if (Chbox.Checked == true)
{
SaveData(eid, uname);
}
lblmsg.Text = "Data Inserted Successfully..";
lblmsg.Visible = true;
}
}
void SaveData(String eid, String uname)
{
SqlConnection con = new SqlConnection(conString);
try
{
con.Open();
com = new SqlCommand("insert into EmpInfo values('" + eid + "','" + uname + "')", con);
com.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}