protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // Find the value in the c04_oprogrs column. You'll have to use

                string value = e.Row.Cells[3].Text;
                City objCity = new City();
                DataTable dtCity = objCity.SelectCityById(Convert.ToInt32(value));
                if (dtCity.Rows.Count > 0)
                {
                    e.Row.Cells[3].Text = dtCity.Rows[0]["CityName"].ToString();
                }
                else
                {
                    e.Row.Cells[3].Text = "No US City";
                }
            }
        }
        protected void btnBuy_Click(object sender, EventArgs e)
        {
            if (Session["UserId"] == null)
                Response.Redirect("Login.aspx");
            else
            {
                if (ddlDeliType.SelectedIndex != 0)
                {
                #region .. GET HISTORY ID ..
                int intHistoryId = 0;
                    objCart = new CartDetails();
                DataTable dtMax = objCart.SelectMaxID();
                if (dtMax.Rows.Count > 0)
                {
                    string st = dtMax.Rows[0]["HistroyId"].ToString();
                    if (dtMax.Rows[0]["HistroyId"].ToString() == "")
                        intHistoryId = 0;
                    else
                        intHistoryId = Convert.ToInt32(dtMax.Rows[0]["HistroyId"].ToString());
                }
                intHistoryId++;
                #endregion
                    #region .. BUY DETAILS ..

                DataTable dtCart = objCart.SelectUserCartDetails(Convert.ToInt32(Session["UserId"].ToString()));
                    double delPrice = 0;
                    int intChargeId = int.Parse(ddlDeliType.SelectedItem.Value.ToString().Trim());

                    ChargeDetails chg = new ChargeDetails();
                    DataTable dt = chg.SelectChargeDetailsByID(intChargeId);
                    string strType = "";
                    string strAmount = "";
                    if (dt.Rows.Count > 0)
                    {
                        strType = dt.Rows[0]["ChargeType"].ToString();
                        strAmount = dt.Rows[0]["AmountOrPercent"].ToString();
                    }

                    double dblDeliAmount = Convert.ToDouble(strAmount);
                    if (strType == "0")
                        delPrice = Convert.ToDouble(decTotalPrice) + dblDeliAmount;
                    else if (strType == "1")
                        delPrice = Convert.ToDouble(decTotalPrice) + (Convert.ToDouble(decTotalPrice) * (dblDeliAmount / 100));

                    string strLocationId = "";
                    string strLocationName = "";
                    if (Session["Location"] != null)
                        strLocationName = Session["Location"].ToString();

                    City objCity = new City();
                    DataTable dtCity = objCity.SelectCityByName(strLocationName);
                    if (dtCity.Rows.Count > 0) strLocationId = dtCity.Rows[0]["CityId"].ToString(); else strLocationId = "0";

                for (int i = 0; i < dtCart.Rows.Count; i++)
                {

                    objCart.CreateBuyDetails(
                        Convert.ToInt32(dtCart.Rows[i]["AdPostId"].ToString()),
                        intHistoryId,
                        Convert.ToInt32(Session["UserId"].ToString()),
                            Convert.ToDecimal(delPrice),
                            int.Parse(ddlDeliType.SelectedItem.Value.ToString().Trim()),
                            Convert.ToInt32(strLocationId),
                        "BOUGHT",
                            1,
                            ddlDeliType.SelectedItem.Text.ToString().Trim(),
                            Convert.ToInt32(strType),
                            Convert.ToDouble(strAmount)
                        );

                    objCart.UpdateCartStatus(Convert.ToInt32(dtCart.Rows[i]["AdPostId"].ToString()), Convert.ToInt32(Session["UserId"].ToString()));
                }
                    decTotalPrice = 0;

                #endregion
                Response.Redirect("MyPurchases.aspx");
            }
                else
                {
                    lblError.Visible = true;
                    lblError.Text = "Select Delivery charges";
                }

            }
        }
 void LoadCity()
 {
     City cnt = new City();
     ddlCity.Items.Clear();
     DataTable dt1 = cnt.SelectCity();
     ListItem listItem = new ListItem();
     listItem.Text = "<Select City>";
     listItem.Value = "0";
     //listItem.Attributes.Add("style", "background-Black:white;color:White");
     ddlCity.Items.Add(listItem);
     for (int i = 0; i < dt1.Rows.Count; i++)
     {
         listItem = new ListItem();
         listItem.Text = dt1.Rows[i]["CityName"].ToString();
         listItem.Value = dt1.Rows[i]["CityId"].ToString();
         //listItem.Attributes.Add("style", "background-color:Black;color:white");
         ddlCity.Items.Add(listItem);
     }
     //ddlCountry.SelectedIndex = 0;
 }