PopulateCategoryDropdown() - This function will be used to populate the two Category dropdown boxes (In the Add and Modify Product Groups) that we have in this tab. These dropdown boxes will hold the category of the products available in the inventory. The category value in the Products repeats through the records many times since a lot of products belong to the same category. So here we need to filter out the unique values and add them to the Category dropdown boxes.
As we can see in the above function, by using a LINQ statement we have recovered the values of the Product_Category column from the Products table. The problem here is that the values recovered here will have repeating values while we only want unique values. So here, we encapsulate the LINQ statement into brackets and add ".Distinct()" after it. This is a LINQ function which effectively filters out unique values from the retrieved result set. So now we only have unique values for the category dropdown box.
Now, we have to bind the retrieved values to the dropdown boxes. For this purpose we use "foreach" statement to traverse through the values. We use the "var" keyword and assign it to "category" which will represent individual values in the "categories" resultset. Apart from that, we assign the values to a dropdown box normally and pass "category" as the value.