2
Answers

Displaying a Pivod table in a report viewer or gridview

Benjamin Allen

Benjamin Allen

8y
328
1

Compliments everyone.

Please how can I display a pivot table or columns in a report viewer or gridview? I tried but only the unpivoted columns were displayed in the report viewer on the webform as the pivoted columns weren't available for selection to be displayed in the report viewer.


Above is my screenshot and below is code behind

CODE BEHIND:


protected void Page_Load(object sender, EventArgs e)     {         if (!IsPostBack)         {             ReportViewer1.ProcessingMode = ProcessingMode.Local;             ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/AttendanceReport.rdlc");             MyDatabaseDataSet dsStudents = GetData();             ReportDataSource datasource = new ReportDataSource("DataSet1", dsStudents.Tables[0]);             ReportViewer1.LocalReport.DataSources.Clear();             ReportViewer1.LocalReport.DataSources.Add(datasource);         }     }     private MyDatabaseDataSet GetData()     {         string connString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;         SqlCommand cmd = new SqlCommand("GetAttendanceTable");         using (SqlConnection con = new SqlConnection(connString))         {             using (SqlDataAdapter sda = new SqlDataAdapter())             {                 cmd.Connection = con;                 cmd.CommandType = CommandType.StoredProcedure;                 sda.SelectCommand = cmd;                 using (MyDatabaseDataSet dsStudents = new MyDatabaseDataSet())                 {                     sda.Fill(dsStudents, "AttendanceTable");                     return dsStudents;                 }             }

        }     }

Thank You.

 

Answers (2)