using System;using System.Collections.Generic;using System.Configuration;using System.Data;using System.Data.SqlClient;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn("regNo", typeof(int)), new DataColumn("FirstName", typeof(string)), new DataColumn("LastName",typeof(string)) }); dt.Rows.Add(1, "John Hammond", "United States"); dt.Rows.Add(2, "Mudassar Khan", "India"); dt.Rows.Add(3, "Suzanne Mathews", "France"); dt.Rows.Add(4, "Robert Schidner", "Russia"); GridView1.DataSource = dt; GridView1.DataBind(); } } protected void Button2_Click(object sender, EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { int regNo = Convert.ToInt32(row.Cells[0].Text.Trim()); string firstName = row.Cells[1].Text.Trim(); string lastName = row.Cells[2].Text.Trim(); string boxDay = TxtBoxDay.Text.Trim(); DateTime boxDate = Convert.ToDateTime(TxtBoxDate.Text.Trim()); string hours = DropDownList5.SelectedItem.Text.Trim(); string status = string.Empty; string authorized = string.Empty;
CheckBox cbStatus = (CheckBox)row.FindControl("cbStatus"); if (cbStatus.Checked) { status = "A"; } else { status = "P"; }
CheckBox cbAuthorized = (CheckBox)row.FindControl("cbAuthorized"); if (cbAuthorized.Checked) { authorized = "O"; } else { authorized = string.Empty; } InsertAttendance(regNo, firstName, lastName, boxDay, boxDate, hours, status, authorized); } Response.Write("Record Added Successfully!"); } private void InsertAttendance(int regNo, string firstName, string lastName, string boxDay, DateTime boxDate, string hours, string status, string authorized) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[desktop - lfbfl4s.Attendance.dbo].ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "INSERT INTO AttendanceTable VALUES (@RegNo,@FirstName,@LastName,@BoxDay,@BoxDate,@Hours,@Status,@Authorized)"; cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@RegNo", regNo); cmd.Parameters.AddWithValue("@FirstName", firstName); cmd.Parameters.AddWithValue("@LastName", lastName); cmd.Parameters.AddWithValue("@BoxDay", boxDay); cmd.Parameters.AddWithValue("@BoxDate", boxDate); cmd.Parameters.AddWithValue("@Hours", hours); cmd.Parameters.AddWithValue("@Status", status); cmd.Parameters.AddWithValue("@Authorized", authorized); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } }
public object desktop { get; set; }}
showing worng pls help it is almost done