private void BindTopicDetails(AdsCategory[] categories)
        {
            DataTable dtCategories = new DataTable();
            dtCategories.Columns.Add("ID");
            dtCategories.Columns.Add("Title");

            foreach (AdsCategory category in categories)
            {
                dtCategories.Rows.Add(new object[]
                                      {
                                          category.ID,
                                          category.Title,
                                      }
                    );
            }

            DataSource = dtCategories;

            dgAdsCategories.DataSource = dtCategories;
            dgAdsCategories.DataBind();
        }
Example #2
0
        private static AdsCategory[] Fetch(int? id, int? parentID, string title, eSortColumn sortColumn)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader = SqlHelper.ExecuteReader(conn, "FetchAdsCategories", id, parentID, title, sortColumn);

                List<AdsCategory> categories = new List<AdsCategory>();

                while (reader.Read())
                {
                    AdsCategory category = new AdsCategory();

                    category.id = (int)reader["ID"];
                    category.parentID = reader["ParentID"] != DBNull.Value ? (int?) reader["ParentID"] : null;
                    category.title = (string)reader["Title"];

                    categories.Add(category);
                }

                return categories.ToArray();
            }
        }
        protected void btnAddNewCategory_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess)
                return;

            AdsCategory category = new AdsCategory();
            category.Title = "NewCategory";
            category.Save();
            PopulateDataGrid();
        }