protected void ui_gvSearchResults_RowDataBound(object sender, GridViewRowEventArgs e) { DropDownList ddl = (DropDownList)e.Row.FindControl("ui_ddlAssignedTo"); if (e.Row.RowType == DataControlRowType.DataRow) { ListItem item = new ListItem(" --- Not Assigned ----", "-1"); userLogin objUsers = new userLogin(); objUsers.LoadAll(); ddl.DataSource = objUsers.DefaultView; ddl.DataTextField = userLogin.ColumnNames.UserName; ddl.DataValueField = userLogin.ColumnNames.AdminID; ddl.DataBind(); ddl.Items.Insert(0, item); HiddenField hd = (HiddenField)e.Row.FindControl("ui_hdnUserID"); int _userID = -1; if (hd.Value != "") { _userID = int.Parse(hd.Value); } ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(_userID.ToString())); } }
private void BindAssignedUser() { ListItem item = new ListItem(" --- Select ----", "-1"); userLogin objCompany = new userLogin(); objCompany.LoadAll(); ui_drpAssignedUser.DataSource = objCompany.DefaultView; ui_drpAssignedUser.DataTextField = userLogin.ColumnNames.UserName; ui_drpAssignedUser.DataValueField = userLogin.ColumnNames.AdminID; ui_drpAssignedUser.DataBind(); ui_drpAssignedUser.Items.Insert(0, item); if (CodeGlobal.LogedInUser.Privaledge == "user") { ui_drpAssignedUser.SelectedValue = CodeGlobal.LogedInUser.s_AdminID; ui_drpAssignedUser.Enabled = false; } else if (CodeGlobal.LogedInUser.Privaledge == "admin") { ui_drpAssignedUser.SelectedValue = "-1"; ui_drpAssignedUser.Enabled = true; } }