[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6567
  • Last Modified:

<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



0
mugsey
Asked:
mugsey
  • 3
  • 3
1 Solution
 
gauravjoshiCommented:
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

0
 
mugseyAuthor Commented:
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
0
 
gauravjoshiCommented:
pls send me skin  and gridview code

I would like to test it on my pc

Gaurav
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mugseyAuthor Commented:
HI Gaurav

Thanks for your comment.  I will have to wait until Monday now but will post asap!
Thanks!
0
 
mugseyAuthor Commented:

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

0
 
gauravjoshiCommented:
<asp:GridView runat="server" SkinId="GridViewSkin" CssClass="gv" CellPadding=5>
    <AlternatingRowStyle CssClass="alt" />
    <FooterStyle CssClass="footer" />
    <SelectedRowStyle CssClass="selected" />
 <EmptyDataTemplate>
        No Records found
    </EmptyDataTemplate>
</asp:GridView>


Try this out, also just make sure, the text font color is not white, i mean it is not getting mixed with background,


Gaurav
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now