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(); } }