I have been checking many other similar questions but I couldn’t find an answer. I have a situation where I need to show UI a Grid whose values will be pull out from a vertical data table.
For instance, let’s say, In the UI I have to show a grid like below based on the P_ID from database product table
Product name | IsLaunched | Exp_Price |
---|---|---|
AC1 | 1 | 4000 |
AC2 | 0 | 3000 |
AC3 | 0 | 3000 |
The values in the Grid will be populated from Database , which is stored in the product table like below:
P_ID | Product name | IsLaunched | Exp_Price |
---|---|---|---|
1 | LCD TV | 1 | 2000 |
1 | LED TV | 1 | 2000 |
2 | AC1 | 1 | 4000 |
2 | AC2 | 0 | 3000 |
2 | AC3 | 0 | 3000 |
so if I select 2 from the drop-down , the result grid should show all the products which have the p_id as 2.
3
Answers
So here is the solution which i implemented which i felt like might be usefull for other who have a similar query.
In .aspx page
In aspx.cs page
and in Stored procedure
Example query that results with the data of your example
So far, so good. Now, we need to make sure that we dynamically receive the value set in the dropdown. That means that on the UI some event happens that changes a value. If you are working on a web app, then this will probably be a request parameter that your server-side will need to handle. If it’s a desktop application, then the backend of the application needs to handle the event. Anyway, depending on the application stack you use, you will need to process the value, build a parameterized query where you pass the chosen ID (and protect against SQL injection shenanigans) to a query executor, which will ultimately run the query and return the results.
You can do that with filtering by P_ID: