public void PopulateGridView() { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["PharmacyConnectionString"].ConnectionString); DataTable dt = new DataTable(); conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM CategoryList", conn); adapter.Fill(dt); if (dt.Rows.Count > 0) { ViewState["Paging"] = dt; CategoryGridView.DataSource = dt; CategoryGridView.DataBind(); CategoryTextBox.Text = ""; ViewState["dirState"] = dt; ViewState["sortdr"] = "Asc"; } else { CategoryGridView.DataSource = dt; CategoryGridView.DataBind(); LblSuccess.Text = ""; LblError.Text = "No record found.....!!!!"; } }
protected void ProductGridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { MessageUserControl.TryRun(() => { GridViewRow row = ProductGridView.Rows[e.NewSelectedIndex]; int partId = int.Parse((row.FindControl("PartID") as HiddenField).Value); var qutity = int.Parse((row.FindControl("Qutity") as TextBox).Text); if (qutity > 0) { var securityController = new SecurityController(); var employeeId = securityController.GetCurrentUserEmployeeId(User.Identity.Name); if (employeeId != null || User.IsInRole("Administrators")) { throw new Exception("Employee or Administrators can't shopping"); } else { var controller = new SalesController(); controller.AddToCart(User.Identity.Name, partId, qutity); //Item.QuantityInCart != 0?Item.QuantityInCart.ToString():"" ProductGridView.DataBind(); CategoryGridView.DataBind(); } } else { throw new Exception("Quantities should geater than 0"); } }, "Successful", "you added a part"); }
protected void Page_Load(object sender, EventArgs e) { var connString = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; var sqlString = "SELECT * FROM ProductSubcategory ORDER BY Name"; using (var conn = new SqlConnection(connString)) { var command = new SqlCommand(sqlString, conn); command.Connection.Open(); CategoryGridView.DataSource = command.ExecuteReader(); CategoryGridView.DataBind(); } }
/************************************************************************* * * GUI update methods * * ***********************************************************************/ protected void ClearAllGridviews() { RecipeGridView.DataSource = null; RecipeGridView.DataBind(); IngredientGridView.DataSource = null; IngredientGridView.DataBind(); CategoryGridView.DataSource = null; CategoryGridView.DataBind(); ContextGridView.DataSource = null; ContextGridView.DataBind(); ltInstructions.Text = "Please select recipe to view recipe details."; Gv_imgs.DataSource = null; Gv_imgs.DataBind(); }
protected void insertButton_Click(object sender, EventArgs e) { sc.Open(); string insertcat = "insert into [dbo].[Category] values (@ProgramType, @ProgramName, @LastUpdatedBy, @LastUpdated)"; SqlCommand insertCatcmd = new SqlCommand(insertcat, sc); insertCatcmd.Parameters.AddWithValue("@ProgramType", addType.SelectedItem.Value); insertCatcmd.Parameters.AddWithValue("@ProgramName", addCategoryName.Text); insertCatcmd.Parameters.AddWithValue("@LastUpdatedBy", Session["User"]); insertCatcmd.Parameters.AddWithValue("@LastUpdated", DateTime.Now); insertCatcmd.ExecuteNonQuery(); CategoryGridView.DataBind(); sc.Close(); }
protected void EditButton_Click(object sender, EventArgs e) { sc.Open(); string editCat = "Update [dbo].[Category] set ProgramType = @ProgramType, ProgramName = @ProgramName, LastUpdatedBy = @LastUpdatedBy, LastUpdated = @LastUpdated where CategoryID = @CategoryID"; SqlCommand editCatcmd = new SqlCommand(editCat, sc); editCatcmd.Parameters.AddWithValue("@ProgramType", EditType.SelectedItem.Value); editCatcmd.Parameters.AddWithValue("@ProgramName", EditName.Text); editCatcmd.Parameters.AddWithValue("@CategoryID", CategoryGridView.SelectedRow.Cells[2].Text); editCatcmd.Parameters.AddWithValue("@LastUpdatedBy", Session["User"]); editCatcmd.Parameters.AddWithValue("@LastUpdated", DateTime.Now); editCatcmd.ExecuteNonQuery(); CategoryGridView.DataBind(); sc.Close(); }
protected void CategoryGridView_RowCommand(object sender, GridViewCommandEventArgs e) { string categoryId = e.CommandArgument.ToString(); if (e.CommandName.Equals("DeleteData")) { try { CategoryBLL.DeleteCategory(categoryId); SystemMessages.DisplaySystemMessage(Resources.Categories.MessageDeletedCategory); CategoryGridView.DataBind(); } catch (Exception exc) { SystemMessages.DisplaySystemErrorMessage(exc.Message); } } else if (e.CommandName.Equals("EditData")) { Category theData = null; try { theData = CategoryBLL.GetCategoryById(categoryId); } catch (Exception exc) { SystemMessages.DisplaySystemErrorMessage(exc.Message); } if (theData != null) { IDTextBox.Text = theData.ID; IDTextBox.ReadOnly = true; NameTextBox.Text = theData.Name; pnlEditData.Visible = true; CategoryIdHiddenField.Value = theData.ID; } } else if (e.CommandName.Equals("ViewItems")) { Session["CATEGORYID"] = categoryId; Response.Redirect("~/Category/CategoryDetails.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable CategoryDataTable = new DataTable(); CategoryDataTable.Columns.Add("CategoryName"); using (SqlConnection connection = Utility.ServerConnection.Connection()) { connection.Open(); using (SqlCommand getCategories = Utility.ServerConnection.GetCategories(connection)) { SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT CategoryName, CategoryID FROM Categories WHERE Active=1", connection); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); CategoryGridView.DataSource = dataSet.Tables[0]; CategoryGridView.DataBind(); } } CategoryGridView.Visible = true; SubCategoryGridView.Visible = false; AddSubCategory.Visible = false; InsertNewCategory.Visible = false; NewCategoryText.Visible = false; InsertNewSubCategory.Visible = false; NewSubCategoryText.Visible = false; DeleteCategory.Visible = false; DeleteSubCategory.Visible = false; EditCategory.Visible = false; EditSubCategory.Visible = false; EditCategoryTextBox.Visible = false; EditSubCategoryTextBox.Visible = false; InsertEditCategory.Visible = false; InsertEditSubCategory.Visible = false; CancelNewCategory.Visible = false; CancelNewSubCategory.Visible = false; CancelEditCategory.Visible = false; CancelEditSubCategory.Visible = false; } }
protected void CategoryGridView_Sorting(object sender, GridViewSortEventArgs e) { DataTable dt = (DataTable)ViewState["dirState"]; if (dt.Rows.Count > 0) { if (Convert.ToString(ViewState["sortdr"]) == "Asc") { dt.DefaultView.Sort = e.SortExpression; ViewState["sortdr"] = "Desc"; } else { dt.DefaultView.Sort = e.SortExpression; ViewState["sortdr"] = "Asc"; } CategoryGridView.DataSource = dt; CategoryGridView.DataBind(); } }
protected void SaveButton_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } if (string.IsNullOrEmpty(CategoryIdHiddenField.Value)) { try { CategoryBLL.InsertCategory(IDTextBox.Text.Trim(), NameTextBox.Text.Trim()); SystemMessages.DisplaySystemMessage(Resources.Categories.MessageCreatedCategory); } catch (Exception exc) { SystemMessages.DisplaySystemErrorMessage(exc.Message); return; } } else { try { CategoryBLL.UpdateCategory(IDTextBox.Text.Trim(), NameTextBox.Text.Trim()); SystemMessages.DisplaySystemMessage(Resources.Categories.MessageUpdatedCategory); } catch (Exception exc) { SystemMessages.DisplaySystemErrorMessage(exc.Message); return; } } CategoryIdHiddenField.Value = ""; pnlEditData.Visible = false; CategoryGridView.DataBind(); }
void BindGrid(string categoryName = "") { DataTable dt = null; try { ApiResponse response = Helper.GetCategories(categoryName); if (response.responseCode == ApiResponse.Success) { InventoryUi.Models.Category[] data = JsonConvert.DeserializeObject <InventoryUi.Models.Category[]>(response.data.ToString()); dt = Helper.CreateDataTable(data); } else if (response.responseCode == ApiResponse.NoDataFound) { TxtId.Text = ""; TxtDescription.Text = ""; LblErrorMsg.Text = "No Data Found"; LblErrorMsg.Visible = true; } else if (response.responseCode == ApiResponse.Exception) { TxtId.Text = ""; TxtDescription.Text = ""; LblErrorMsg.Text = "Api Error: " + response.error; LblErrorMsg.Visible = true; } } catch (Exception ex) { TxtDescription.Text = ""; LblErrorMsg.Text = "Page Error: " + ex.Message; LblErrorMsg.Visible = true; } CategoryGridView.DataSource = dt; CategoryGridView.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { //Create instance of dataAdapter SqlDataAdapter adapter = new SqlDataAdapter("spGetProductAndCategoriesData", con); //set adapter command type adapter.SelectCommand.CommandType = CommandType.StoredProcedure; //Create instance of DataSet for storing result in memory DataSet dataSet = new DataSet(); //call fill() which automatically open connection and execute query and close connection adapter.Fill(dataSet); dataSet.Tables[0].TableName = "Products"; dataSet.Tables[1].TableName = "Categories"; ProductsGridView.DataSource = dataSet.Tables["Products"]; ProductsGridView.DataBind(); CategoryGridView.DataSource = dataSet.Tables["Categories"]; CategoryGridView.DataBind(); } }
protected void UpdateReceipeDetailsGridViews(int recipeId) { using (Models.PlanMyDinnerDbContext database = new Models.PlanMyDinnerDbContext()) { IngredientGridView.DataSource = database.Recipes.Find(recipeId).Ingredients.ToList(); IngredientGridView.DataBind(); CategoryGridView.DataSource = database.Recipes.Find(recipeId).Categories.ToList(); CategoryGridView.DataBind(); ContextGridView.DataSource = database.Recipes.Find(recipeId).Contexts.ToList(); ContextGridView.DataBind(); ltInstructions.Text = addHtmlBreakTags(database.Recipes.Find(recipeId).Instructions); string CurrentDir = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName; string ImagePath = System.IO.Path.Combine(CurrentDir, "Media/" + database.Recipes.Find(recipeId).ThumbFileName); List <ListItem> Imgs = new List <ListItem>(); string ImgName = Path.GetFileName(ImagePath); Imgs.Add(new ListItem(ImgName, "~/Media/" + ImgName)); Gv_imgs.DataSource = Imgs; Gv_imgs.DataBind(); } }
protected void CategoryGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { CategoryGridView.PageIndex = e.NewPageIndex; CategoryGridView.DataSource = ViewState["Paging"]; CategoryGridView.DataBind(); }
private void BindData() { CategoryGridView.DataBind(); }