コード例 #1
0
    string storeList = ""; // The string that will contain the stores that the user selected

    protected void Page_Load(object sender, EventArgs e)
    {
        // Only run on initial page load
        if (!IsPostBack)
        {
            // Populate the checked box with data from the store table
            tStoreTableAdapter      storeTableAdapter = new tStoreTableAdapter();
            dsStore.tStoreDataTable storeDataTable    = storeTableAdapter.GetData();
            cbStore.DataTextField  = "StoreWithAddress";
            cbStore.DataValueField = "Store";
            cbStore.DataSource     = storeDataTable;
            cbStore.DataBind();
        }
    }
コード例 #2
0
    /// <summary>
    /// Populate the dropdown and checkboxlist with appropriately formatted data
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            OpenConnection();
            //Populating the Product dropdown.
            tProductTableAdapter          productTypeAdapter = new tProductTableAdapter();
            ds_Products.tProductDataTable products           = productTypeAdapter.GetData();

            /*
             * Ref for below code: http://stackoverflow.com/questions/1143639/binding-multiple-fields-to-listbox-in-asp-net/
             * In all honesty not entirely sure how this works...
             * Is this kinda like a Lambda Function?
             * Specifically looked for this though to keep formatting out of the data layer.
             */
            EnumerableRowCollection productData = from product in products
                                                  select new
            {
                Name = product.Name + " - " + product.Description + " :by " + product.Manufacturer,
                Id   = product.ProductID
            };
            //end code I don't fully understand
            //The rest is just normal data binding.
            ddProducts.DataSource     = productData;
            ddProducts.DataTextField  = "Name";
            ddProducts.DataValueField = "Id";
            ddProducts.DataBind();

            //Use dataset to populate check box list
            tStoreTableAdapter       storeTypeAdapter = new tStoreTableAdapter();
            ds_Store.tStoreDataTable storeDataTable   = storeTypeAdapter.GetData();
            cblStores.DataTextField  = "StoreString";
            cblStores.DataValueField = "StoreID";
            cblStores.DataSource     = storeDataTable;
            cblStores.DataBind();
            cblStores.SelectedIndex = 0;
        }
    }