Hello....i want to create one table in aspx.net.I am using gridview in order to make the table. The things is I want to include the data row by row inside gridview using different sql statements...here I try to upload the template that I want as of my output.If anyone can help me in term of ideas, I'm really appreciate it...Thank.

Dani AI

Generated

— two practical ways to build the grid you sketched: push the aggregation into SQL (recommended for performance) or build rows in code and bind a DataTable. and asked for specifics, so below are concrete examples and tips.

A single SQL result (one round trip) is easiest if you can union your alert tables and pivot sectors into columns. Example pattern (SQL Server):

SELECT AlertType, ISNULL([Finance],0) AS Finance, ISNULL([Retail],0) AS Retail, ISNULL([Tech],0) AS Tech
FROM
(
  SELECT 'AlertA' AS AlertType, Sector, COUNT(*) AS Cnt FROM AlertA_Table GROUP BY Sector
  UNION ALL
  SELECT 'AlertB', Sector, COUNT(*) FROM AlertB_Table GROUP BY Sector
  UNION ALL
  SELECT 'AlertC', Sector, COUNT(*) FROM AlertC_Table GROUP BY Sector
) AS src
PIVOT
(
  SUM(Cnt)
  FOR Sector IN ([Finance],[Retail],[Tech])
) AS pvt
ORDER BY AlertType;

If sectors are dynamic or you prefer app logic, build a DataTable programmatically: get the distinct sector list first, create columns (AlertType + sector columns), then loop alert tables, run COUNT(*) WHERE Sector=@sector for each sector, fill DataRow, add to DataTable, and bind to GridView (GridView.DataSource = dataTable; GridView.DataBind();).

Quick tips:

  • Prefer the single-query pivot when possible — fewer DB round trips and easier sorting.
  • If sectors are not known ahead, query SELECT DISTINCT Sector FROM ... and create columns dynamically before binding.
  • Use parameterized queries or a stored procedure for safety and maintainability.
  • Handle NULLs (use ISNULL in SQL or coalesce in code) and define consistent column types (int).
  • For GridView, set AutoGenerateColumns=true for quick binding, or create Bound/TemplateFields programmatically when you need formatting.

Either approach will let the first column be the alert type and subsequent columns show company counts per sector.

Recommended Answers

All 3 Replies

That is broad question. Please be more specific.

Hey...
can u be more specific about ur question pls..

sorry...

actually like this.I want to create table as above picture in aspx.The first column is the types of alerts and the rest is sum of the companies based on sector. all data will get from database.Every types of alerts has their own table in database.So, i need to call sql select statement for each alert. My question is after I call sql statement, how I need to include the data from sql statement in gridview.It is because I have a different select statement and need to add row for every statement..

It is clear for you guys??I'm really does not have any ideas for this...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.