Link to home
Start Free TrialLog in
Avatar of mugsey
mugseyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

<EmptyDataTemplate> NOT WORKING ON GRIDVIEW CONTROL

I have a gridview

                    <asp:GridView ID="grdSearchResults" runat="server"
                    AutoGenerateColumns="False" DataKeyNames="PropertyID"
                    onselectedindexchanged="grdSearchResults_SelectedIndexChanged"
                    SkinID="GridViewSkin"
                    EmptyDataText="No properties have been returned - create new property below">
                        <columns>
                            <asp:boundfield DataField="PropertyID" Visible="False"></asp:boundfield>
                            <asp:boundfield DataField="Address1" HeaderText="Address"></asp:boundfield>
                            <asp:boundfield DataField="PostCode" HeaderText="Post Code"></asp:boundfield>
                            <asp:commandfield SelectText="Select This Property" ShowSelectButton="True">                          
                            </asp:commandfield>
</columns>    
                    </asp:GridView>


Here is the code to populate using subsonic..........

            Query qry = new Query("ClientProperty");
            qry.QueryType = QueryType.Select;
            if (txtAddress1.Text.Length > 1)
            {
                qry.AddWhere("ClientProperty", "Address1", Comparison.Like, txtAddress1.Text);
            }
            if (txtPostCode.Text.Length > 1)
            {
                qry.AddWhere("ClientProperty", "PostCode", Comparison.Like, txtPostCode.Text);
            }

            IDataReader myReader = qry.ExecuteReader();
            grdSearchResults.DataSource = myReader;
            grdSearchResults.DataBind();
            myReader.Close();


However if no results are returned the emptydatatemplate does not display



Avatar of gauravjoshi
gauravjoshi
Flag of United States of America image

create EmptyDataTemplate node and put your template inside it.

you can add this to your skin file if you have same msg to appear for all the grids you using.


Gaurav
<asp:GridView SkinId="SkinGridView"  runat="server" >
    <EmptyDataTemplate>
        No Records found
    </EmptyDataTemplate>
</asp:GridView>

Open in new window

Avatar of mugsey

ASKER

HI

Thanks I did this but still no text appears
If records are found then the gridview is displayed - else if no records then nothing
pls send me skin  and gridview code

I would like to test it on my pc

Gaurav
Avatar of mugsey

ASKER

HI Gaurav

Thanks for your comment.  I will have to wait until Monday now but will post asap!
Thanks!
Avatar of mugsey

ASKER


Here is the gridview CSS
 
TABLE.gv
{
   border-bottom:solid 2px #aaaaaa;
   width:100%; 
}
 
 
TABLE.gv TH
{
    background-color:#8f8ab6;
    color:#ffffff;
}
 
TABLE.gv TH a,
TABLE.gv TH a:link,
TABLE.gv TH a:active,
TABLE.gv TH a:hover,
TABLE.gv TH a:visited
{
    color:#ffffff;
}
 
TABLE.gv TR.footer
{
    background-color:#cccccc;
}
 
TABLE.gv TR.alt
{
    background-color:#F5FAFA;
}
 
TABLE.gv TR.selected
{
    background-color:Highlight;
    color:#ffffff;
}
 
TABLE.gv TR.selected a
{
   color:#ffffff; 
}
 
****************
 
Here is the gridview skin
 
 
<asp:GridView runat="server" SkinId="GridViewSkin" CssClass="gv" CellPadding=5>
    <AlternatingRowStyle CssClass="alt" />
    <FooterStyle CssClass="footer" />
    <SelectedRowStyle CssClass="selected" />        
</asp:GridView>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gauravjoshi
gauravjoshi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial