private void GridBind()
        {
            try
            {
                DAL = new DataAccessLayer();
                DataTable dtbl = DAL.GetAllRoles();
                grdViewRoles.DataSource = dtbl;
                grdViewRoles.DataBind();

                DropDownList ddl = grdViewRoles.FooterRow.FindControl("ddlInsertCandidateName") as DropDownList;

                List <ListItem> Candidate_Name = new List <ListItem>();

                Dictionary <string, string> list = DAL.GetCandidatename();
                foreach (KeyValuePair <string, string> entry in list)
                {
                    Candidate_Name.Add(new ListItem(entry.Key, entry.Value.ToString()));
                }
                ddl.Items.AddRange(Candidate_Name.ToArray());
            }
            catch (Exception ex)
            {
                lblException.Visible   = true;
                lblException.Text      = "Grid Bind Exception: " + ex.Message;
                lblException.ForeColor = System.Drawing.Color.Red;
            }
        }
        private void GridSearch()
        {
            lblException.Visible = false;
            string txtSearchValue = txtSearch.Text.ToLower();
            int    length         = txtSearchValue.Length;

            try
            {
                if (length >= 3)
                {
                    DAL = new DataAccessLayer();
                    DataTable dtbl     = DAL.GetSearchRoles(ddlSearch.SelectedValue, txtSearch.Text);
                    int       countrow = dtbl.Rows.Count;
                    if (countrow == 0)
                    {
                        lblSearchError.Visible   = true;
                        lblSearchError.Text      = "No Records Found";
                        lblSearchError.ForeColor = System.Drawing.Color.Red;
                        grdViewRoles.Visible     = false;
                        lblException.Visible     = false;
                    }
                    else
                    {
                        lblSearchError.Visible  = false;
                        grdViewRoles.Visible    = true;
                        grdViewRoles.DataSource = dtbl;
                        grdViewRoles.DataBind();

                        DropDownList                ddl            = grdViewRoles.FooterRow.FindControl("ddlInsertCandidateName") as DropDownList;
                        List <ListItem>             Candidate_Name = new List <ListItem>();
                        Dictionary <string, string> list           = DAL.GetCandidatename();
                        foreach (KeyValuePair <string, string> entry in list)
                        {
                            Candidate_Name.Add(new ListItem(entry.Key, entry.Value.ToString()));
                        }
                        ddl.Items.AddRange(Candidate_Name.ToArray());
                    }
                }
                else
                {
                    lblErrorMessage.Visible  = false;
                    lblSearchError.Visible   = true;
                    lblSearchError.Text      = "Please enter minimum 3 characters";
                    lblSearchError.ForeColor = System.Drawing.Color.Red;
                    lblException.Visible     = false;
                }
            }
            catch (Exception ex)
            {
                lblErrorMessage.Visible = false;
                lblException.Visible    = true;
                lblException.Text       = "Grid Search Exception: " + ex.Message;
                lblException.ForeColor  = System.Drawing.Color.Red;
            }
        }
        protected void grdViewRoles_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DAL = new DataAccessLayer();

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList ddl = (DropDownList)e.Row.FindControl("ddlEditCandidateName");

                if (ddl != null)
                {
                    List <ListItem> Candidate_Name = new List <ListItem>();
                    ddl.SelectedIndex = 1;
                    Dictionary <string, string> list = DAL.GetCandidatename();
                    foreach (KeyValuePair <string, string> entry in list)
                    {
                        Candidate_Name.Add(new ListItem(entry.Key, entry.Value.ToString()));
                    }
                    ddl.Items.AddRange(Candidate_Name.ToArray());
                    DataRowView dr = e.Row.DataItem as DataRowView;
                    ddl.SelectedValue = dr["Candidate_Name"].ToString();
                }
            }
        }