public void UpdateGridview() { //SqlConnection conn = new SqlConnection(@"data source = DESKTOP-6CQP77U; integrated security = true; database = PestUpdated"); SqlConnection conn = new SqlConnection(@"data source = localhost\SQLEXPRESS; integrated security = true; database = pestupdate"); SqlDataReader rdr = null; try { conn.Open(); SqlCommand cmd = new SqlCommand("Select * from Help WHERE idcustomer = '" + Session["id"] + "'", conn); // SqlCommand cmd = new SqlCommand("Select * from Help WHERE idcustomer = 1", conn); rdr = cmd.ExecuteReader(); GridViewUser.DataSource = rdr; GridViewUser.DataBind(); } catch (Exception ex) { swag.Text = ex.Message; } finally { conn.Close(); // SqlDataAdapter closes connection by itself; but can fail in case of errors. } }
/// <summary> /// /// </summary> protected void GridViewUser_Sorting(object sender, GridViewSortEventArgs e) { //Specify the direction in which to sort a list of items as ascending SortDirection sortDirection = SortDirection.Ascending; string sortField = string.Empty; SortGridview((GridView)sender, e, out sortDirection, out sortField); string strSortDirection = sortDirection == SortDirection.Ascending ? "ASC" : "DESC"; // Create connection to SQL Server using (SqlConnection con = new SqlConnection(CS)) { //Create a DataAdapter, and then provide the name of the stored procedure. SqlDataAdapter da = new SqlDataAdapter("spSortGridViewByField", con); //Set the command type as StoredProcedure. da.SelectCommand.CommandType = CommandType.StoredProcedure; //Create and add a parameter to Parameters collection for the stored procedure. da.SelectCommand.Parameters.AddWithValue("@UserId", Convert.ToInt32(Session["UserId"])); da.SelectCommand.Parameters.AddWithValue("@SortExpression", e.SortExpression.ToString()); da.SelectCommand.Parameters.AddWithValue("@SortDirection", strSortDirection); // Create a new DataSet to hold the records. DataSet DS = new DataSet(); // Fill the DataSet with the rows that are returned. da.Fill(DS); // Set the data source for the GridView as the DataSet that holds the rows. GridViewUser.DataSource = DS; GridViewUser.DataBind(); } }
protected void OnSorting(object sender, GridViewSortEventArgs e) { DataTable dtable = ViewState["dirState"] as DataTable; if (dtable.Rows.Count > 0) { if (Convert.ToString(ViewState["sortdr"]) == "Asc") { dtable.DefaultView.Sort = e.SortExpression + " Desc"; ViewState["sortdr"] = "Desc"; Session["SortedView"] = e.SortExpression + " Desc"; } else { dtable.DefaultView.Sort = e.SortExpression + " Asc"; ViewState["sortdr"] = "Asc"; Session["SortedView"] = e.SortExpression + " Asc"; } GridViewUser.DataSource = dtable; GridViewUser.DataBind(); } }
protected void ButtonAddUser_OnClick(object sender, EventArgs e) { Business.Users.AddUser(Convert.ToInt32(TextBoxUserNId.Text), TextBoxUserName.Text, TextBoxUserSurname.Text, TextBoxUserGender.Text, TextBoxUserNationality.Text, TextBoxUserLanguage.Text, TextBoxUserProfession.Text, Convert.ToDateTime(TextBoxUserBirthday.Text), TextBoxUserPhone.Text, TextBoxUserEmail.Text, TextBoxUserPassword.Text); GridViewUser.DataSource = Business.Users.GetAllUsers(); GridViewUser.DataBind(); }
void FillGrid_User() { if ((string)Session["AdminSessionID"] != null) { string xCode = Session["AdminSessionID"].ToString(); SqlDataAdapter GDA = new SqlDataAdapter(" " + " select Code, PlannerName=PlannerName+'-'+(Select left(Name,1) from fp_ComboDetail where Code=p.PlannerRole ) " + " ,UserID,Pwd,City,Mobile=Mobile1,Website, PlannerRole=(Select Name from fp_ComboDetail " + " where Code=p.PlannerRole ), " + " ReportTo=(select Name from fp_prospects where Code=p.ReportTo) from fp_Planner p " + " ", Con); DataSet GDS = new DataSet(); Con.Open(); GDA.Fill(GDS); Con.Close(); GridViewUser.DataSource = GDS; GridViewUser.DataBind(); } else { Response.Redirect("SessionExpired.aspx"); } }
void PopulateGridview() { DataTable dtbl = new DataTable(); using (SqlConnection sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); SqlDataAdapter sqlDa = new SqlDataAdapter("SELECT * FROM UserData ", sqlCon); sqlDa.Fill(dtbl); if (dtbl.Rows.Count > 0) { GridViewUser.DataSource = dtbl; GridViewUser.DataBind(); } else { dtbl.Rows.Add(dtbl.NewRow()); GridViewUser.DataSource = dtbl; GridViewUser.DataBind(); GridViewUser.Rows[0].Cells.Clear(); GridViewUser.Rows[0].Cells.Add(new TableCell()); GridViewUser.Rows[0].Cells[0].ColumnSpan = dtbl.Columns.Count; GridViewUser.Rows[0].Cells[0].Text = "No Data Found ..!"; GridViewUser.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; } } }
protected void Page_Load(object sender, EventArgs e) { this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None; string strSQLUser = null; string strSQLMessage = null; strSQLUser = "******"; connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("VanierFaces.accdb") + ";Persist Security Info=False;"); connection.Open(); cmd = new OleDbCommand(strSQLUser, connection); OleDbDataAdapter adpU = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); adpU.Fill(ds); GridViewUser.DataSource = ds; GridViewUser.DataBind(); strSQLMessage = "SELECT sender, message, date_sent FROM tblMessages WHERE receiver = 'ewq'"; cmd = new OleDbCommand(strSQLMessage, connection); OleDbDataAdapter adpM = new OleDbDataAdapter(cmd); DataSet dsM = new DataSet(); adpM.Fill(dsM); GridViewMessage.DataSource = dsM; GridViewMessage.DataBind(); username = Session["username"].ToString(); userProfile = Session["userProfile"].ToString(); }
// get the existing users from users table. // show the users details below save/update button. private void BindGridView() { try { if (conn.State == ConnectionState.Closed) { conn.Open(); } // sql query to get the list of users SqlCommand cmd = new SqlCommand("select id as \"User Id\",fname+' '+lname as Name, sex as Gender, dob as \"Date of Birth\",mobile as \"Mobile No\", email as \"Email Id\" from users order by id;", conn); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); GridViewUser.DataSource = ds; GridViewUser.DataBind(); lbltotalcount.Text = GridViewUser.Rows.Count.ToString(); } catch (SqlException ex) { throw ex; } finally { conn.Close(); } }
public void loadUserslist() { List <UsersModel> list = Logic.LoadUsers(); GridViewUser.DataSource = list; GridViewUser.DataBind(); if (list.Count != 0) { int totalRecords = list.Count(); int pageSize = 5; int totalPages = totalRecords / pageSize; if (totalRecords % 5 > 0) { totalPages += 1; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < totalPages; i++) { int pageNo = i + 1; sb.Append("<a style=\"color: #FFFFFF\" href=\"ViewUsers.aspx?StartIndex=" + pageSize * i + "\">" + pageNo.ToString() + "</a> "); int GridPagingNumber = pageSize * i; Session["GridPagingNumber"] = GridPagingNumber; } Literal.Text = "Page: " + sb.ToString(); GridViewUser.DataSource = list.Skip(StartIndex).Take(5); GridViewUser.DataBind(); } else { lblNoData.Text = "There are no Users."; Literal.Text = " "; } }
protected void OnSearch(object sender, EventArgs e) { string searchTerm = searchBox.Text.ToLower(); if (searchTerm.Length >= 3) { if (ViewState["dirState"] == null) { return; } DataTable dtable = ViewState["dirState"] as DataTable; DataTable dtableNew = dtable.Clone(); foreach (DataRow row in dtable.Rows) { if (row["first_name"].ToString().ToLower().Contains(searchTerm)) { dtableNew.Rows.Add(row.ItemArray); } } GridViewUser.DataSource = dtableNew; GridViewUser.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridViewUser.DataSource = bllUserInfo.GetAllList().Tables[0]; GridViewUser.DataBind(); } }
protected void btnupdate_Click(object sender, EventArgs e) //update button { try { User_Mangement bl = new User_Mangement(); Business B = new Business(); b.User_Id = txtuserid.Text.Trim(); b.Name = TextBoxName.Text.Trim(); b.Department_Id = DDLdeptname.SelectedValue; b.EmailId = txtemailid.Text.Trim(); b.InstituteId = DDLinstitutename.SelectedValue; if (txtDOB.Text != "01/01/0001" && txtDOB.Text != null && txtDOB.Text != "") { b.StudentDOB = Convert.ToDateTime(txtDOB.Text.Trim()); } if (txtMobileNo.Text != "") { b.MobileNo = txtMobileNo.Text; } b.Sex = DropDownListsex.SelectedValue; //b.BankAccountNumber = txtaccno.Text; b.CreatedDate = DateTime.Now.ToString("yyyy-MM-dd"); b.UpdatedBy = Session["UserId"].ToString(); string OldmailID = Session["OldmailID"].ToString(); int isupdatemailid = 0; if (OldmailID != "") { if (OldmailID != b.emailId) { isupdatemailid = 1; } } //if (b.Role_Id == 1) //{ // b.pubinchargedept = RadioButtonListDeparmentPubincharge.SelectedValue; //} // int retemail = bl.Updatestudentmailid(txtemailid.Text, b, isupdatemailid, OldmailID); // b.Role_Name = DDLrolename.SelectedValue; int retVal = bl.UpdateStudentdetails(b); //Business layer ClientScript.RegisterStartupScript(Page.GetType(), "validation1", "<script language='javascript'>alert('User detail update successfully')</script>"); //btninsert.Enabled = false; txtemailid.Enabled = false; popupPanelBaCode.Visible = false; GridViewUser.DataBind(); GridViewUser.Visible = false; } catch (Exception ex) { log.Error(ex.StackTrace); log.Error(ex.Message); log.Error("Error!!!!!!!!!!!!!!!! "); ClientScript.RegisterStartupScript(Page.GetType(), "validation1", "<script language='javascript'>alert('Error!!!!!!!!!!')</script>"); } }
private void binddata() { string usertype = Session["usertype"].ToString(); DataSet DS = new DataSet(); DS = UserBLL.Instance.getallusers(usertype); GridViewUser.DataSource = DS.Tables[0]; GridViewUser.DataBind(); }
protected void OnResetSearch(object sender, EventArgs e) { if (ViewState["dirState"] == null) { return; } DataTable dtable = ViewState["dirState"] as DataTable; searchBox.Text = ""; GridViewUser.DataSource = dtable; GridViewUser.DataBind(); }
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e) { GridViewUser.PageIndex = e.NewPageIndex; if (Session["SortedView"] != null) { DataTable dtable = ViewState["dirState"] as DataTable; dtable.DefaultView.Sort = Session["SortedView"].ToString(); GridViewUser.DataSource = dtable; GridViewUser.DataBind(); } else { BindGridView(); } }
private void SearchSubmit() { logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name); try { string user_id = (ddlSearchFirst_Name.SelectedIndex == 0 ? string.Empty : ddlSearchFirst_Name.SelectedItem.Value); string role = (ddlSearchRole.SelectedIndex == 0 ? string.Empty : ddlSearchRole.SelectedItem.Value); string PositionKey = (ddlSearchPosition.SelectedIndex == 0 ? string.Empty : ddlSearchPosition.SelectedItem.Value); string region = string.Empty; foreach (ListItem item in ddlSearchState.Items) { if (item.Selected && item.Text != "==ระบุ==") { if (string.IsNullOrEmpty(region)) { region = item.Text; } else { region = region + "," + item.Text; } } } List <dbo_UserClass> dt = dbo_UserDataClass.Search(user_id, string.Empty, PositionKey, string.Empty, ddlSearchStatus.Text, "CP Meiji", role, string.Empty, null, string.Empty, region); if (dt.Count > 0) { GridViewUser.DataSource = dt; GridViewUser.DataBind(); showPanel("pnlGrid"); GridViewUser.Visible = true; pnlNoRec.Visible = false; } else { GridViewUser.Visible = false; pnlNoRec.Visible = true; } } catch (Exception) { } }
protected void Page_Load(object sender, EventArgs e) { DataTable panelPopup = new DataTable(); panelPopup.Columns.Add("Input"); panelPopup.Columns.Add("Name"); panelPopup.Columns.Add("Output"); createActionTable("User", panelPopup); GridViewUser.DataSource = panelPopup; GridViewUser.DataBind(); panelPopup.Clear(); createActionTable("Friend", panelPopup); GridViewFriends.DataSource = panelPopup; GridViewFriends.DataBind(); panelPopup.Clear(); createActionTable("Album", panelPopup); GridViewAlbum.DataSource = panelPopup; GridViewAlbum.DataBind(); panelPopup.Clear(); createActionTable("Photo", panelPopup); GridViewPhoto.DataSource = panelPopup; GridViewPhoto.DataBind(); panelPopup.Clear(); createActionTable("Post", panelPopup); GridViewPost.DataSource = panelPopup; GridViewPost.DataBind(); panelPopup.Clear(); createActionTable("Video", panelPopup); GridViewVideo.DataSource = panelPopup; GridViewVideo.DataBind(); panelPopup.Clear(); createActionTable("Like", panelPopup); GridViewLike.DataSource = panelPopup; GridViewLike.DataBind(); panelPopup.Clear(); createActionTable("Comment", panelPopup); GridViewComment.DataSource = panelPopup; GridViewComment.DataBind(); }
protected void srcbtn_Click(object sender, EventArgs e) { con.Open(); SqlCommand cmd = new SqlCommand(); string query = "Select *from UserInfo where AccID like '%'+@AccNo+'%' "; cmd.CommandText = query; cmd.Connection = con; cmd.Parameters.AddWithValue("@AccNo", SearchBox.Text); DataTable dt = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dt); GridViewUser.DataSource = dt; GridViewUser.DataBind(); con.Close(); }
private void LoadData() { using (SqlConnection sqlconn = new SqlConnection(conStr)) { using (SqlCommand cmd = new SqlCommand()) { sqlconn.Open(); cmd.Connection = sqlconn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "getAllUser"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); GridViewUser.DataSource = dt; GridViewUser.DataBind(); } } }
protected void btnupdate_Click(object sender, EventArgs e) //update button { try { Business B = new Business(); b.User_Id = txtuserid.Text; b.Role_Id = Convert.ToInt32(DDLrolename.SelectedValue); b.InstituteId = DDLinstitutename.SelectedValue; b.emailId = txtemailid.Text; string OldmailID = Session["OldmailID"].ToString(); b.CreatedBy = Session["UserId"].ToString(); int isupdatemailid = 0; if (OldmailID != "") { if (OldmailID != b.emailId) { isupdatemailid = 1; } } if (b.Role_Id == 1) { b.pubinchargedept = RadioButtonListDeparmentPubincharge.SelectedValue; } int retemail = B.Updatemailid(txtemailid.Text, b, isupdatemailid, OldmailID); // b.Role_Name = DDLrolename.SelectedValue; int retVal = bl.Update(b); //Business layer ClientScript.RegisterStartupScript(Page.GetType(), "validation1", "<script language='javascript'>alert('User detail update successfully')</script>"); //btninsert.Enabled = false; txtemailid.Enabled = false; popupPanelBaCode.Visible = false; GridViewUser.DataBind(); GridViewUser.Visible = false; } catch (Exception ex) { log.Error(ex.StackTrace); log.Error(ex.Message); log.Error("Error!!!!!!!!!!!!!!!! "); ClientScript.RegisterStartupScript(Page.GetType(), "validation1", "<script language='javascript'>alert('Error!!!!!!!!!!')</script>"); } }
public void btnSearchCancel_Click(object sender, System.EventArgs e) { logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name); SetUpDrowDownList(); showPanel("pnlGrid"); if (GridViewUser.Rows.Count > 0) { List <dbo_UserClass> dt = new List <dbo_UserClass>(); GridViewUser.DataSource = dt; GridViewUser.DataBind(); } GridViewUser.Visible = false; pnlNoRec.Visible = false; System.Threading.Thread.Sleep(500); ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true); }
protected void BindGridView() { connection = new MySqlConnection(connectionStr); connection.Open(); queryStr = "SELECT * FROM user_info JOIN favourite_foods ON user_info.user_id = favourite_foods.user_id"; command = new MySqlCommand(queryStr, connection); MySqlDataAdapter sqlAdapter = new MySqlDataAdapter(command); DataTable dtable = new DataTable(); sqlAdapter.Fill(dtable); connection.Close(); GridViewUser.DataSource = dtable; GridViewUser.DataBind(); ViewState["dirState"] = dtable; ViewState["sortdr"] = "Asc"; }
/// <summary> /// Binding data from stored procedure to Grid View /// </summary> private void BindData() { try { // Create connection to SQL Server using (SqlConnection con = new SqlConnection(CS)) { // Create a DataAdapter, and then provide the name of the stored procedure. SqlDataAdapter da = new SqlDataAdapter("spGetUserDetailsbyUserId", con); // Set the command type as StoredProcedure. da.SelectCommand.CommandType = CommandType.StoredProcedure; // Create and add parameter to Parameters collection for the stored procedure. da.SelectCommand.Parameters.AddWithValue("@UserId", Session["UserId"]); // Create a new DataSet to hold the records. DataSet DS = new DataSet(); // Fill the DataSet with the rows that are returned. da.Fill(DS); // Set the data source for the GridView as the DataSet that holds the rows. GridViewUser.DataSource = DS; if (DS.Tables[0].Rows.Count == 0) { lblMessage.Text = "No users yet......"; } else { GridViewUser.DataBind(); } } } catch (Exception ex) { ErrorMessage.Text = ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { User us = (User)Session["user"]; if (Session["user"] != null) { if (us.RoleID == 1) { GridViewUser.DataSource = ViewUserController.getUser(); GridViewUser.DataBind(); } else { Response.Redirect("Home.aspx"); } } else { Response.Redirect("Home.aspx"); } } }
private void BindInsightSupplierContactGridView() { GridViewUser.DataSource = InsightSupplierContact.GetInsightSupplierContactListByInsightSupplierId(Convert.ToInt32(ViewState["InsightSupplierId"])); GridViewUser.DataBind(); }
protected void GridViewUser_RowDeleted(object sender, GridViewDeletedEventArgs e) { GridViewUser.DataBind(); }
private void GridViewDataBind() { if (ItemDataProcess.type == itemType) { if (Session["AuthenticatedAdminData"] != null) { GridViewAdmin.DataSource = ItemDataProcess.GetItems(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdmin.DataBind(); //this.DataBind() değil GridView’in DataBind()’i çağrıldı } else { GridViewUser.DataSource = ItemDataProcess.GetItems(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewUser.DataBind(); //this.DataBind() değil GridView’in DataBind()’i çağrıldı } } else if (ItemDataProcess.type == bookType) { if (Session["AuthenticatedAdminData"] != null) { GridViewAdminDistinct.DataSource = ItemDataProcess.GetBooks(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdminDistinct.DataBind(); } else { GridViewUserDistinct.DataSource = ItemDataProcess.GetBooks(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewUserDistinct.DataBind(); } } else if (ItemDataProcess.type == journalType) { if (Session["AuthenticatedAdminData"] != null) { GridViewAdminDistinct.DataSource = ItemDataProcess.GetJournals(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdminDistinct.DataBind(); } else { GridViewUserDistinct.DataSource = ItemDataProcess.GetJournals(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewUserDistinct.DataBind(); } } else if (ItemDataProcess.type == newspaperType) { if (Session["AuthenticatedAdminData"] != null) { GridViewAdminDistinct.DataSource = ItemDataProcess.GetNewspapers(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdminDistinct.DataBind(); } else { GridViewUserDistinct.DataSource = ItemDataProcess.GetNewspapers(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewUserDistinct.DataBind(); } } else if (ItemDataProcess.type == videoType) { if (Session["AuthenticatedAdminData"] != null) { GridViewAdminDistinct.DataSource = ItemDataProcess.GetVideos(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdminDistinct.DataBind(); } else { GridViewUserDistinct.DataSource = ItemDataProcess.GetVideos(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewUserDistinct.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { GridViewUser.DataSource = Business.Users.GetAllUsers(); GridViewUser.DataBind(); }
protected void ButtonDelete_OnClick(object sender, EventArgs e) { Business.Users.DeleteUser(Convert.ToInt32(TextBoxId.Text)); GridViewUser.DataSource = Business.Users.GetAllUsers(); GridViewUser.DataBind(); }