protected void ddlBusiness1_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddlBusiness11 = (DropDownList)GridView1.Rows[GridView1.EditIndex].FindControl("ddlBusiness1"); // Label whid = (Label)gridocsubsubtype.Rows[gridocsubsubtype.EditIndex].FindControl("lblw"); DropDownList ddlcat11 = (DropDownList)GridView1.Rows[GridView1.EditIndex].FindControl("ddlcat1"); // Label lblCategory11 = (Label)GridView1.Rows[GridView1.EditIndex].FindControl("lblCategory"); //String s = "select * from JobFunctionCategory where Whid = '" + ddlBusiness11.SelectedValue + "'"; //da = new SqlDataAdapter(s, con); //ds = new DataSet(); //da.Fill(ds); CLS_JobFunctionSubCategory jfs = new CLS_JobFunctionSubCategory(); jfs.Whid = ddlBusiness11.SelectedValue; ds = jfs.cls_select1(); ddlcat11.DataSource = ds; ddlcat11.DataTextField = "CategoryName"; ddlcat11.DataValueField = "Id"; ddlcat11.DataBind(); }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { int dk = Convert.ToInt32(GridView1.DataKeys[GridView1.EditIndex].Value); TextBox txtcat = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtSubcat1"); CheckBox cb = (CheckBox)GridView1.Rows[e.RowIndex].FindControl("cbxStatus1"); DropDownList ddlBusiness11 = (DropDownList)GridView1.Rows[GridView1.EditIndex].FindControl("ddlBusiness1"); DropDownList ddlcat11 = (DropDownList)GridView1.Rows[GridView1.EditIndex].FindControl("ddlcat1"); //string str1 = "SELECT * from JobFunctionSubCategory where SubCategoryName ='" + txtcat.Text + "' and JobCategoryId ='" + ddlcat11.SelectedValue + "' and Id<>'" + dk + "'"; //SqlCommand cmd1 = new SqlCommand(str1, con); //SqlDataAdapter da1 = new SqlDataAdapter(cmd1); //DataTable dt1 = new DataTable(); //da1.Fill(dt1); CLS_JobFunctionSubCategory jfs = new CLS_JobFunctionSubCategory(); jfs.SubCategoryName = txtcat.Text; jfs.JobCategoryId = ddlcat11.SelectedValue; jfs.Id = dk.ToString(); DataTable dt1 = jfs.cls_selectsubcategory(); if (dt1.Rows.Count > 0) { lblmsg.Visible = true; lblmsg.Text = "SubCategory already exist"; } else { int i; if (cb.Checked == true) { i = 1; } else { i = 0; } string sr51 = ("update JobFunctionSubCategory set SubCategoryName ='" + txtcat.Text + "',JobCategoryId ='" + ddlcat11.SelectedValue + "',Status = " + i + " where Id='" + dk + "' "); SqlCommand cmd801 = new SqlCommand(sr51, con); if (con.State.ToString() != "Open") { con.Open(); } cmd801.ExecuteNonQuery(); con.Close(); //jfs.SubCategoryName = txtcat.Text; // jfs.JobCategoryId = ddlcat11.SelectedValue; //jfs.Id = dk.ToString(); //jfs.cls_update(); GridView1.EditIndex = -1; fillgrid(); lblmsg.Visible = true; lblmsg.Text = "Record updated successfully"; } } catch (Exception ert) { lblmsg.Visible = true; lblmsg.Text = "Error :" + ert.Message; } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { int i = Convert.ToInt32(e.CommandArgument); String s = "select * from JobFunction where JobfunctionsubcategoryId = " + i; SqlDataAdapter da = new SqlDataAdapter(s, con); ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { lblmsg.Visible = true; lblmsg.Text = "Sorry, you are unable to delete this sub category as there are job functions exist using this sub category."; } else { CLS_JobFunctionSubCategory jfs = new CLS_JobFunctionSubCategory(); jfs.Id = i.ToString(); jfs.cls_delete(); lblmsg.Visible = true; lblmsg.Text = "Record deleted successfully"; fillgrid(); } } if (e.CommandName == "Edit") { int i = Convert.ToInt32(e.CommandArgument); ViewState["EID"] = i; String s = "select JobFunctionSubCategory.*,WareHouseMaster.Name,JobFunctionCategory.Whid from JobFunctionSubCategory inner join JobFunctionCategory on JobFunctionCategory.Id=JobFunctionSubCategory.JobCategoryId inner join WareHouseMaster on WareHouseMaster.WareHouseId=JobFunctionCategory.Whid where JobFunctionSubCategory.Id = " + i; SqlDataAdapter da = new SqlDataAdapter(s, con); DataTable dtf = new DataTable(); da.Fill(dtf); if (dtf.Rows.Count > 0) { btnSubmit.Text = "Update"; lbllegend.Text = "Edit Job Function SubCategory"; lblmsg.Text = ""; Panel4.Visible = true; btnnewcat.Visible = false; txtSubCategory.Text = dtf.Rows[0]["SubCategoryName"].ToString(); if (Convert.ToString(dtf.Rows[0]["Status"]) == "True") { ddlStatus.SelectedValue = "1"; } else { ddlStatus.SelectedValue = "0"; } fillddl_business(); test(); ddlbusiness.SelectedIndex = ddlbusiness.Items.IndexOf(ddlbusiness.Items.FindByValue(dtf.Rows[0]["Whid"].ToString())); fillddl_category(); ddlcategory.SelectedIndex = ddlcategory.Items.IndexOf(ddlcategory.Items.FindByValue(dtf.Rows[0]["JobCategoryId"].ToString())); } } }