Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Gridview with Name Gridview1
I have a SqlDatasource with Name SqlDatasource1
I have a TextBox which can search SqlDatasource1
i have code like below
C#
protected void ButtonSearch_Click(object sender, EventArgs e)
   {
      SqlDataSource1.SelectCommand = "SELECT *FROM GOMSNO747 WHERE APPLICATIONNO='" + TextBoxApplicantionNumber.Text + "'";
    }

It works well when Record Found
When No Record Found I need to Show a Label with the Name No Record Found
I used <emptydatatemplate>No Record Found
The Problem is it sinks GridView Caption and No Record Found have a line around
In order to solve this i used below code

C#
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (e.AffectedRows == 0)
        {
            //Label1.Text = "Hai Krishna";
            LabelNoRecord.Text = "No Record Found";

        }


    }


But the Problem is it display No Record even if the Record is Founded also
The Reason is SELECT command is not effect the Rows
How to solve this Problem
Posted

Hi krishna,

you have to set the property
C#
GridView.EmptyDataText = "No Record". 


if you have no record
 
Share this answer
 
Comments
krishna_goluguri 31-Oct-11 2:00am    
The Problem is it sinks GridView Caption
GridView.EmptyDataText is Nothing But a <emptydatatemplate>No Record Found in GridView
krishna_goluguri 31-Oct-11 2:03am    
my question is changed
in the gridview we have Empty Data Template there we can set No Record Found But it shrinks my Gridview Caption GridView.Empty Data Text and EmptyDataTemplate are same
In ur code just make a small modification

C#
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (e.AffectedRows == 0)
        {
            //Label1.Text = "Hai Krishna";
            LabelNoRecord.Visible=True;
            LabelNoRecord.Text = "No Record Found";

        }
       else
        {
        LabelNoRecord.Visible=False;

        }


    }
 
Share this answer
 
Comments
krishna_goluguri 31-Oct-11 2:41am    
here The AffectedRows are always 0 because select command wont effect rows

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900