Esempio n. 1
0
 protected void ddCategory_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ddCategory != null && ddCategory.SelectedIndex > 0 && ddSubCategory != null)
     {
         int selCategoryId = Convert.ToInt32(ddCategory.SelectedValue);
         ddSubCategory.DataSource     = AdminDb.GetSubcategoriesByCategory(selCategoryId);
         ddSubCategory.DataTextField  = "SubCategoryName";
         ddSubCategory.DataValueField = "SubCategoryID";
         ddSubCategory.DataBind();
     }
 }
        protected void ddCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddCategory = (DropDownList)sender;
            GridViewRow  currentRow = (GridViewRow)ddCategory.NamingContainer;

            DropDownList ddSubcategory = (DropDownList)currentRow.FindControl("ddSubcategory");

            if (ddCategory != null && ddCategory.SelectedIndex > 0 && ddSubcategory != null)
            {
                int selCategoryId = Convert.ToInt32(ddCategory.SelectedValue);
                ddSubcategory.DataSource     = AdminDb.GetSubcategoriesByCategory(selCategoryId);
                ddSubcategory.DataTextField  = "SubCategoryName";
                ddSubcategory.DataValueField = "SubCategoryID";
                ddSubcategory.DataBind();
            }
        }
        protected void gvListings_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
            {
                DataRowView Row = (DataRowView)e.Row.DataItem;

                //Bind the categories dd
                DropDownList ddCategory = (DropDownList)e.Row.FindControl("ddCategory");
                ddCategory.DataSource     = AdminDb.GetCategories();
                ddCategory.DataTextField  = "CategoryName";
                ddCategory.DataValueField = "CategoryID";
                ddCategory.DataBind();

                ddCategory.SelectedValue = Row["CategoryID"].ToString();
                //Bind the state dropdown list
                DropDownList ddState = (DropDownList)e.Row.FindControl("ddState");

                ddState.DataSource     = AdminDb.GetStates();
                ddState.DataTextField  = "Statename";
                ddState.DataValueField = "StateID";
                ddState.DataBind();

                int stateId = Convert.ToInt32(Row["StateID"]);

                ddState.SelectedValue = Row["StateID"].ToString();
                //Bind the edit city drop down list
                DropDownList ddCity = (DropDownList)e.Row.FindControl("ddCity");

                ddCity.DataSource     = AdminDb.GetCitiesByState(stateId);
                ddCity.DataTextField  = "CityName";
                ddCity.DataValueField = "CityID";
                ddCity.DataBind();

                ddCity.SelectedValue = Row["CityID"].ToString();

                //Bind the edit subcategory drop down list
                int          CategoryID    = Convert.ToInt32(Row["CategoryID"]);
                DropDownList ddSubcategory = (DropDownList)e.Row.FindControl("ddSubcategory");

                ddSubcategory.DataSource     = AdminDb.GetSubcategoriesByCategory(CategoryID);
                ddSubcategory.DataTextField  = "SubCategoryName";
                ddSubcategory.DataValueField = "SubCategoryID";
                ddSubcategory.DataBind();

                ddSubcategory.SelectedValue = Row["SubCategoryID"].ToString();
            }
        }
Esempio n. 4
0
        protected void gvListings_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditListing")
            {
                int       listingID    = Convert.ToInt32(e.CommandArgument);
                DataTable listingTable = AdminDb.GetListingByID(listingID);
                DataRow   row          = listingTable.Rows[0];
                lbListingId.Text   = listingID.ToString();
                tbHeadline.Text    = row["Headline"].ToString();
                tbLocation.Text    = row["Location"].ToString();
                lbUserID.Text      = row["UserID"].ToString();
                tbPrice.Text       = row["Price"].ToString();
                tbDescription.Text = row["Description"].ToString();
                cbIsActive.Checked = Convert.ToBoolean(row["IsActive"]);

                //Bind the categories dd
                ddCategory.DataSource     = AdminDb.GetCategories();
                ddCategory.DataTextField  = "CategoryName";
                ddCategory.DataValueField = "CategoryID";
                ddCategory.DataBind();

                ddCategory.SelectedValue = row["CategoryID"].ToString();

                int catID = Convert.ToInt32(row["CategoryID"].ToString());

                //Bind the state dropdown list
                ddState.DataSource     = AdminDb.GetStates();
                ddState.DataTextField  = "Statename";
                ddState.DataValueField = "StateID";
                ddState.DataBind();

                int stateId = Convert.ToInt32(row["StateID"]);

                ddState.SelectedValue = row["StateID"].ToString();

                //Bind the edit city drop down list
                ddCity.DataSource     = AdminDb.GetCitiesByState(stateId);
                ddCity.DataTextField  = "CityName";
                ddCity.DataValueField = "CityID";
                ddCity.DataBind();

                ddCity.SelectedValue = row["CityID"].ToString();

                //Bind the edit subcategory drop down list
                ddSubCategory.DataSource     = AdminDb.GetSubcategoriesByCategory(catID);
                ddSubCategory.DataTextField  = "SubCategoryName";
                ddSubCategory.DataValueField = "SubCategoryID";
                ddSubCategory.DataBind();

                ddSubCategory.SelectedValue = row["SubCategoryID"].ToString();

                //make modal visible and backdrop
                pnlListingEdit.Visible = true;
                pnlBackdrop.Visible    = true;
            }
            else if (e.CommandName == "DeleteListing")
            {
                int listingID = Convert.ToInt32(e.CommandArgument);
                AdminDb.DeleteListing(listingID);
                BindDataToGridView();
            }
        }