Hi phonghue,
Follow the below steps.
1. In the report designer right click on the column TextBox and select Text Box Properties...
2. Inside Text Box Properties dialog select Visibility tab and select Show hide based on an expression and select fx button.
3. Then write the expression.
=IIf(Fields!Item.Value <> "", false, true)
4. Click OK.
5. Repeat above steps for all TextBox.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
</rsweb:ReportViewer>
Namespaces
C#
using System.Data;
using Microsoft.Reporting.WebForms;
VB.Net
Imports System.Data
Imports Microsoft.Reporting.WebForms
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Item");
dt.Columns.Add("SRate", typeof(int));
dt.Columns.Add("Qty", typeof(int));
dt.Columns.Add("TotalPrice", typeof(int));
dt.Columns.Add("SalesID", typeof(int));
dt.Columns.Add("Discount", typeof(int));
dt.Rows.Add("Item 1", 10, 10, 100, 1, 10);
dt.Rows.Add("", 10, 10, 100, 1, 10);
dt.Rows.Add("Item 2", 10, 10, 100, 1, 10);
dt.Rows.Add("Item 3", 10, 10, 100, 1, 10);
decimal totalSales = Convert.ToDecimal(dt.Compute("SUM(TotalPrice)", string.Empty));
DataTable res = dt.AsEnumerable().GroupBy(r => r["SalesID"]).Select(g => g.First()).CopyToDataTable();
decimal totalDiscount = Convert.ToDecimal(res.Compute("SUM(Discount)", string.Empty));
decimal finalPrice = totalSales + totalDiscount;
Sales dsSales = new Sales();
foreach (DataRow dr in dt.Rows)
{
dsSales.Tables[0].Rows.Add(dr["Item"].ToString(), dr["SRate"].ToString(), dr["Qty"], dr["TotalPrice"]);
}
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
ReportDataSource datasource = new ReportDataSource("Sales", dsSales.Tables[0]);
ReportViewer1.LocalReport.Refresh();
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.Add("Item")
dt.Columns.Add("SRate", GetType(Integer))
dt.Columns.Add("Qty", GetType(Integer))
dt.Columns.Add("TotalPrice", GetType(Integer))
dt.Columns.Add("SalesID", GetType(Integer))
dt.Columns.Add("Discount", GetType(Integer))
dt.Rows.Add("Item 1", 10, 10, 100, 1, 10)
dt.Rows.Add("", 10, 10, 100, 1, 10)
dt.Rows.Add("Item 2", 10, 10, 100, 1, 10)
dt.Rows.Add("Item 3", 10, 10, 100, 1, 10)
Dim totalSales As Decimal = Convert.ToDecimal(dt.Compute("SUM(TotalPrice)", String.Empty))
Dim res As DataTable = dt.AsEnumerable().GroupBy(Function(r) r("SalesID")).[Select](Function(g) g.First()).CopyToDataTable()
Dim totalDiscount As Decimal = Convert.ToDecimal(res.Compute("SUM(Discount)", String.Empty))
Dim finalPrice As Decimal = totalSales + totalDiscount
Dim dsSales As Sales = New Sales()
For Each dr As DataRow In dt.Rows
dsSales.Tables(0).Rows.Add(dr("Item").ToString(), dr("SRate").ToString(), dr("Qty"), dr("TotalPrice"))
Next
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
Dim datasource As ReportDataSource = New ReportDataSource("Sales", dsSales.Tables(0))
ReportViewer1.LocalReport.Refresh()
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(datasource)
End If
End Sub
Screenshot