Hello Developers,
I am developing an web application and i need to create report using reportveiewer.
I am successully able to fetch and display record in reportviewer now,
But if no record found then it will disply only header with all Fields.
Insted of this fields ,I want to Display Message "No Record Available".
Below is mail Sourccode that is working.
Report.aspx code:

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" Height="400px" Width="100%">
            <LocalReport ReportPath="RegistrationReport.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" 
                        Name="RegistrationReport_MsdWebcast_GetRegisterUserTrainingEventsWise" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>
        <asp:ObjectDataSource  ID="ObjectDataSource1"  runat="server" SelectMethod="GetData" 
            OldValuesParameterFormatString="original_{0}" 
            TypeName="RegistrationReportTableAdapters.MsdWebcast_GetRegisterUserTrainingEventsWiseTableAdapter">
            <SelectParameters>
                <asp:QueryStringParameter  Name="TrainingEventsID" 
                    QueryStringField="TEID" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

No extra code in because of everthing is manage by aspx code that i mention above.


Please help.......
"Everthing that your Dynamic mind get is Possible :E=MC2"

Dani AI

Generated

As pointed out, you can check the result count and show a label instead of the report. Below are two reliable, evergreen ways to do that for an ObjectDataSource + local RDLC setup (the TableAdapter you're using typically returns a DataTable or a collection).

  1. Code-behind (recommended when using ObjectDataSource)
  • Add a Label on the page (e.g. lblNoRecords, initially Visible="false").
  • Wire the ObjectDataSource OnSelected event and inspect e.ReturnValue in the handler. The handler works whether your SelectMethod returns a DataTable, DataSet or a List<T>.
protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
    if (e.Exception != null) { e.ExceptionHandled = true; lblNoRecords.Text = "Error loading data"; lblNoRecords.Visible = true; ReportViewer1.Visible = false; return; }

    var dt = e.ReturnValue as System.Data.DataTable;
    if (dt != null) {
        bool empty = dt.Rows.Count == 0;
        lblNoRecords.Visible = empty;
        ReportViewer1.Visible = !empty;
        if (empty) lblNoRecords.Text = "No Record Available";
        return;
    }

    var list = e.ReturnValue as System.Collections.IEnumerable;
    if (list != null) {
        bool empty = !list.Cast<object>().Any(); // requires using System.Linq
        lblNoRecords.Visible = empty;
        ReportViewer1.Visible = !empty;
        if (empty) lblNoRecords.Text = "No Record Available";
        return;
    }

    // fallback
    lblNoRecords.Visible = true;
    ReportViewer1.Visible = false;
    lblNoRecords.Text = "No Record Available";
}
  1. RDLC designer (no code)
  • In the report designer select the Tablix (table) and set its NoRowsMessage (or add a small textbox whose Hidden expression uses CountRows("DataSetName")). This shows the message inside the report when the dataset is empty and avoids toggling controls in code.

Notes and pitfalls

  • Don’t use Response.Write on Page_Load to show the message — it can break the page markup/report output.
  • If your SelectMethod returns a strongly‑typed DataTable, cast to that type instead of DataTable.
  • Handle e.Exception in the Selected event to surface real errors separately from “no rows.”

This ties ’s row-count idea into the ObjectDataSource lifecycle and gives an RDLC alternative if you prefer the message inside the report.

Recommended Answers

All 2 Replies

Put oneLabel on your aspx page where you have dragged your report viewer control. Then check with your datasource.

I mean If (DataTable or DataSet.Tables["yourtablename/index"].Rows.Count == 0) then "Print message No recreds available" in Label.

Hope it will help you.

Hello Developers,
I am developing an web application and i need to create report using reportveiewer.
I am successully able to fetch and display record in reportviewer now,
But if no record found then it will disply only header with all Fields.
Insted of this fields ,I want to Display Message "No Record Available".
Below is mail Sourccode that is working.
Report.aspx code:

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" Height="400px" Width="100%">
            <LocalReport ReportPath="RegistrationReport.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" 
                        Name="RegistrationReport_MsdWebcast_GetRegisterUserTrainingEventsWise" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>
        <asp:ObjectDataSource  ID="ObjectDataSource1"  runat="server" SelectMethod="GetData" 
            OldValuesParameterFormatString="original_{0}" 
            TypeName="RegistrationReportTableAdapters.MsdWebcast_GetRegisterUserTrainingEventsWiseTableAdapter">
            <SelectParameters>
                <asp:QueryStringParameter  Name="TrainingEventsID" 
                    QueryStringField="TEID" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

No extra code in because of everthing is manage by aspx code that i mention above.


Please help.......
"Everthing that your Dynamic mind get is Possible :E=MC2"

Put oneLabel on your aspx page where you have dragged your report viewer control. Then check with your datasource.

I mean If (DataTable or DataSet.Tables["yourtablename/index"].Rows.Count == 0) then "Print message No recreds available" in Label.

Hope it will help you.

How I can know the objectDataSource1 Contained records or not?

WIll you please provide code statement for that?

on page I need

on page load

if(Code to Is count Recourd values from objectDataSource1)
{
Response.Write("No Records Found");
Reportview1.visible=false;
}

Please Reply ,it's very urgent.
Thanks..

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.