예제 #1
0
 protected void IngredientsGrid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "Insert")
     {
         DataTable dt            = new DataTable();
         DataTable newIngredient = new DataTable();
         dt = (DataTable)ViewState["Ingredients"];
         if (dt.Rows.Count < 15)
         {
             Ingridients ing = new Ingridients();
             ing.RecipeId    = Convert.ToInt32(recipeGrid.DataKey.Value.ToString());
             ing.name        = ((TextBox)IngredientsGrid.FooterRow.FindControl("txtName")).Text;
             ing.Quantity    = Convert.ToInt32(((TextBox)IngredientsGrid.FooterRow.FindControl("txtQuantity")).Text);
             ing.measureUnit = ((TextBox)IngredientsGrid.FooterRow.FindControl("txtMeasureUnits")).Text;
             DataRow newIng = dt.NewRow();
             newIng[1] = ing.name;
             newIng[2] = ing.Quantity;
             newIng[3] = ing.measureUnit;
             newIng[4] = ing.RecipeId;
             dt.Rows.Add(newIng);
             ViewState["Ingredients"]   = dt;
             ViewState["NewIngredient"] = ing;
             IngredientsGrid.DataSource = dt;
             IngredientsGrid.DataBind();
         }
         else
         {
             update.Text = "Can't add more than 15 Ingredients ";
         }
     }
 }
예제 #2
0
    //Brinderjit Singh StudentId=300918321

    protected void Page_PreRender(object sender, EventArgs e)
    {
        int recipeId = Convert.ToInt32(Request.QueryString["ID"]);

        if (recipeId == 0)
        {
            Response.Redirect("Recipes.aspx");
        }
        DataTable dr = _objrepositry.getDetails(recipeId);

        recipeGrid.HeaderText = dr.Rows[0]["Name"].ToString().ToUpper();
        string selecteditem = dr.Rows[0]["Category"].ToString();

        if (!Page.IsPostBack)
        {
            ViewState["Recipe"]   = dr;
            recipeGrid.DataSource = dr;
            DataTable dr1 = _objrepositry.getDIngredientDetails(recipeId);
            recipeGrid.DataBind();
            ViewState["Ingredients"]   = dr1;
            IngredientsGrid.DataSource = dr1;
            IngredientsGrid.DataBind();
        }
        else
        {
            recipeGrid.DataSource      = (DataTable)ViewState["Recipe"];
            IngredientsGrid.DataSource = (DataTable)ViewState["Ingredients"];
            recipeGrid.DataBind();
            IngredientsGrid.DataBind();
        }
    }