private void Grid() { SqlConnection cn = new SqlConnection("Data Source=ANCYCHACKO-TOSH;Initial Catalog=tallysoftware;Integrated Security=True"); SqlCommand cmd = new SqlCommand(); DataTable dataTable; dataTable = new DataTable(); cmd.Connection = cn; SqlDataAdapter da = new SqlDataAdapter("select * from Sheet1$ ", cn); System.Data.DataSet ds = new System.Data.DataSet(); da.Fill(ds); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds.Tables[0]; GridView1.DataSource = ds; GridView1.DataBind(); cn.Close(); } } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; Grid(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { e.Cancel = true; GridView1.EditIndex = -1; Grid(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; Grid(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["tallysoftwareConnectionString4"].ConnectionString); SqlCommand cmd = new SqlCommand(); cn.Open(); GridViewRow row = GridView1.Rows[e.RowIndex]; DropDownList dropdownlist1 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("dropdownlist1"); TextBox txtEcollected = (TextBox)row.FindControl("txtEcollected"); TextBox txtEplan = (TextBox)row.FindControl("txtEplan"); TextBox txtEacoll = (TextBox)row.FindControl("txtEacoll"); DropDownList dropdownlist2 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("dropdownlist2"); TextBox txtEre = (TextBox)row.FindControl("txtEre"); TextBox txtEdescrptn = (TextBox)row.FindControl("txtEdescrptn"); //int Id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); string se_name = dropdownlist1.SelectedItem.Text; string collected_date = txtEcollected.Text; string amount_plan = txtEplan.Text; string amount_collected = txtEacoll.Text; string status_ar = dropdownlist2.SelectedItem.Text; string remark = txtEre.Text; string description = txtEdescrptn.Text; Label lblid = (Label)row.FindControl("Label3"); // string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); int id = Convert.ToInt32(lblid.Text); cmd.CommandText = "UPDATE Sheet1$ SET se_name='" + dropdownlist1.SelectedItem.Text + "' ,collected_date ='" + txtEcollected.Text + "',amount_plan ='" + txtEplan.Text + "',amount_collected ='" + txtEacoll.Text + "',status_ar ='" + dropdownlist2.SelectedItem.Text + "',remark='" + txtEre.Text + "',description='" + txtEdescrptn.Text + "' WHERE id=" + id + ""; cmd.Connection = cn; cmd.ExecuteNonQuery(); GridView1.EditIndex = -1; Grid(); cn.Close(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["tallysoftwareConnectionString4"].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cn.Open(); GridViewRow row = GridView1.Rows[e.RowIndex]; Label lblid = (Label)row.FindControl("Label3"); // string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); int id = Convert.ToInt32(lblid.Text); //int Id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); cmd.CommandText = "DELETE FROM Sheet1$ WHERE id='" + id + "' "; cmd.ExecuteNonQuery(); cn.Close(); Grid(); } }
DropDownList dropdownlist1 = (DropDownList).row .FindControl("dropdownlist1");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)