using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using System.Text; public partial class CreateChallan : System.Web.UI.Page { string connStr = ConfigurationManager.ConnectionStrings["amitpandeyConnectionString2"].ConnectionString; protected void btnUpdate_Click(object sender, EventArgs e) { StringBuilder strSql = new StringBuilder(string.Empty); SqlConnection con = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand(); for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox chkUpdate = (CheckBox) GridView1.Rows[i].Cells[0].FindControl("chkSelect"); if (chkUpdate != null) { if (chkUpdate.Checked) { string strDocketNo = GridView1.Rows[i].Cells[1].Text; string strBranchCode = ((TextBox) GridView1.Rows[i].FindControl("txtBranchCode")).Text; string strDate = ((TextBox) GridView1.Rows[i].FindControl("txtDate")).Text; string strPKTS = ((TextBox) GridView1.Rows[i].FindControl("txtPKTS")).Text; string strActWt = ((TextBox) GridView1.Rows[i].FindControl("txtActwt")).Text; string strChargeWt = ((TextBox) GridView1.Rows[i].FindControl("txtChargeWt")).Text; string strMode = ((TextBox) GridView1.Rows[i].FindControl("Mode")).Text; string strChallanNo = ((TextBox) GridView1.Rows[i].FindControl("ChallanNo")).Text; string strChallanDate = ((TextBox) GridView1.Rows[i].FindControl("ChallanDate")).Text; string strVehicleNo = ((TextBox) GridView1.Rows[i].FindControl("VehicleNo")).Text; string strDescription = ((TextBox) GridView1.Rows[i].FindControl("Description")).Text; string strUpdate = "Update CreateDocket set BranchCode = '" + strBranchCode + "', Date = '" + strDate + "', PKTS = '" + strPKTS + "',ActWt = '" + strActWt + "',ChargeWt = '" + strChargeWt + "',Mode = '" + strMode + "',ChallanNo = '" + strChallanNo + "',ChallanDate = '" + strChallanDate + "',VehicleNo = '" + strVehicleNo + "',Description = '" + strDescription + "' WHERE DEocketNo ='" + strDocketNo + "'"; strSql.Append(strUpdate); } } } try { cmd.CommandType = CommandType.Text; cmd.CommandText = strSql.ToString(); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); } catch (SqlException ex) { string errorMsg = "Error in Updation"; errorMsg += ex.Message; throw new Exception(errorMsg); } finally { con.Close(); } } protected void chkSelect_CheckedChanged (object sender, EventArgs e) { CheckBox chkTest = (CheckBox)sender; GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer; TextBox txtBranchCode = (TextBox)grdRow.FindControl ("txtBranchCode"); TextBox txtDate = (TextBox)grdRow.FindControl ("txtDate"); TextBox txtPKTS = (TextBox)grdRow.FindControl ("txtPKTS"); TextBox txtActWT = (TextBox)grdRow.FindControl ("txtActWT"); TextBox txtChargeWt = (TextBox)grdRow.FindControl ("txtChargeWt"); TextBox txtMode = (TextBox)grdRow.FindControl ("txtMode"); TextBox txtChallanNo = (TextBox)grdRow.FindControl ("txtChallanNo"); TextBox txtChallanDate = (TextBox)grdRow.FindControl ("txtChallanDate"); TextBox txtVehicleNo = (TextBox)grdRow.FindControl ("txtVehicleNo"); TextBox txtDescription = (TextBox)grdRow.FindControl ("txtDescription"); if (chkTest.Checked) { txtChallanNo.ReadOnly = false; txtChallanDate.ReadOnly = false; txtVehicleNo.ReadOnly = false; txtDescription.ReadOnly = false; txtChallanNo.ForeColor = System.Drawing.Color.Red; txtChallanDate.ForeColor = System.Drawing.Color.Red; txtVehicleNo.ForeColor = System.Drawing.Color.Red; txtDescription.ForeColor = System.Drawing.Color.Red; } else { txtChallanNo.ReadOnly = true; txtChallanDate.ReadOnly = true; txtVehicleNo.ReadOnly = true; txtDescription.ReadOnly = true; txtChallanNo.ForeColor = System.Drawing.Color.Green; txtChallanDate.ForeColor = System.Drawing.Color.Green; txtVehicleNo.ForeColor = System.Drawing.Color.Green; txtDescription.ForeColor = System.Drawing.Color.Green; } } }
strSql.ToString()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)