Dear Sir,
I want to disable dropdown item while click on Save button.
please help me sir.
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=ocms_admin;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
refreshdata();
}
}
public void refreshdata()
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from comp_box", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=ocms_admin;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
DropDownList DropDownList1 = (e.Row.FindControl("DropDownList1") as DropDownList);
SqlCommand cmd = new SqlCommand("select * from complaint_status", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "STATUS_NAME";
DropDownList1.DataValueField = "STATUS_NAME";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--SELECT_STATUS--", "0"));
DropDownList DropDownList2 = (e.Row.FindControl("DropDownList2") as DropDownList);
cmd = new SqlCommand("select * from Assign_to", con);
sda = new SqlDataAdapter(cmd);
dt = new DataTable();
sda.Fill(dt);
DropDownList2.DataSource = dt;
DropDownList2.DataTextField = "STATUS_NAME";
DropDownList2.DataValueField = "STATUS_NAME";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("--SELECT_NAME--", "0"));
}
}
protected void Update(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
int COMP_ID = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32((sender as Button).CommandArgument)].Values[0]);
string STATUS_ID = (row.FindControl("DropDownList1") as DropDownList).SelectedItem.Text;
string ATTEND_BY = (row.FindControl("DropDownList2") as DropDownList).SelectedItem.Text;
// string remark = (row.FindControl("TextBox5") as TextBox).Text;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE comp_box SET STATUS_ID = @STATUS_ID, ATTEND_BY = @ATTEND_BY WHERE COMP_ID = @COMP_ID"))
{
cmd.Parameters.AddWithValue("@STATUS_ID", STATUS_ID);
cmd.Parameters.AddWithValue("@ATTEND_BY", ATTEND_BY);
cmd.Parameters.AddWithValue("@COMP_ID", COMP_ID);
// cmd.Parameters.AddWithValue("@REMARKS", remark);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
DropDownList2.Items[1].Attributes.Add("disabled", "disabled");
DropDownList2.Items[2].Attributes.Add("disabled", "disabled");
}
}