protected void ddState_SelectedIndexChanged(object sender, EventArgs e) { if (ddState != null && ddState.SelectedIndex > 0 && ddCity != null) { int selStateId = Convert.ToInt32(ddState.SelectedValue); ddCity.DataSource = AdminDb.GetCitiesByState(selStateId); ddCity.DataTextField = "CityName"; ddCity.DataValueField = "CityID"; ddCity.DataBind(); } }
protected void ddState_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddState = (DropDownList)sender; GridViewRow currentRow = (GridViewRow)ddState.NamingContainer; DropDownList ddCity = (DropDownList)currentRow.FindControl("ddCity"); if (ddState != null && ddState.SelectedIndex > 0 && ddCity != null) { int selStateId = Convert.ToInt32(ddState.SelectedValue); ddCity.DataSource = AdminDb.GetCitiesByState(selStateId); ddCity.DataTextField = "CityName"; ddCity.DataValueField = "CityID"; ddCity.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(); } }
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(); } }