Example #1
0
    protected void GvreoderItems_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //To add supplierList to items that are below the reorderLevel
            DropDownList     supplierList  = (DropDownList)e.Row.FindControl("ddlSupplierList");
            Label            itemCodeLbl   = (Label)e.Row.FindControl("lblItemCode");
            String           gvrowItemCode = itemCodeLbl.Text;
            List <ItemPrice> itemPriceList = pCtrlr.GetItemPriceList().Where(x => x.ItemCode == (string)DataBinder.Eval(e.Row.DataItem, "ItemCode")).ToList();
            // List<SupplierInfo> splrList = pCtrlr.GetSupplierListByItemCode(gvrowItemCode);
            supplierList.DataSource     = itemPriceList;
            supplierList.DataTextField  = "SupplierName";
            supplierList.DataValueField = "SupplierCode";
            supplierList.DataBind();


            //To check whether the same item with same supplier has been added to gridview
            // if so, then prepopulate with second supplier for that newly added item
            if (!dictnry.ContainsKey(gvrowItemCode))
            {
                dictnry.Add(gvrowItemCode, 0);
            }
            else
            {
                int value = dictnry[gvrowItemCode];
                dictnry[gvrowItemCode] = value + 1;
            }

            if (itemPriceList.Count > dictnry[gvrowItemCode])
            {
                supplierList.SelectedValue = itemPriceList[dictnry[gvrowItemCode]].SupplierCode;
            }
            else
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox",
                                                   "<script language='javascript'>alert('" + "Item already exist!" + "');</script>");
            }

            Label price = (Label)e.Row.FindControl("lblPrice");
            price.Text = Convert.ToString(itemPriceList.Where(x => x.SupplierCode == supplierList.SelectedValue).Select(x => x.FormattedPrice).First());
            Label amount = (Label)e.Row.FindControl("lblAmount");
            amount.Text = Convert.ToString(itemPriceList.Where(x => x.SupplierCode == supplierList.SelectedValue).Select(x => x.FormattedAmount).First());
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
        }
    }