Uttam Samal

Uttam Samal

  • NA
  • 22
  • 0

How to use the controls in Formview Edit or Insert Mode.

Jun 11 2020 6:43 AM
I wanted to use a Dropdown list box in Formview Edit mode, I'm able to add a Dropdownlist now I need to know how do I access the Dropdown list control in code behind. I tried using
DropDownList ddlContractName = (DropDownList)FormView1.Row.FindControl("ddlContractName") but unable to change any properties.
Also I wanted to hide the Edit button in ReadOnly Mode for some users, that did not work out as well (below is the sample)
private void FormView1_DataBound(object sender, System.EventArgs e)
        {
            if (FormView1.CurrentMode == FormViewMode.ReadOnly)
            {
                string usrRole = Master.getUserRole(Master.GetLoggedOnUser);
                if (usrRole == "Admin")
                {
                    LinkButton linkButton = (LinkButton)FormView1.FindControl("EditButton") as LinkButton;
                    linkButton.Visible = false;
                } else
                {
                    LinkButton linkButton = (LinkButton)FormView1.FindControl("EditButton") as LinkButton;
                    linkButton.Visible = true;
                }
           }
     }

Answers (2)