locked
Empty template support for GridView RRS feed

  • Question

  • User-1390808839 posted

    Just add the following to support the empty text in the GridView.

     

    protected override void RenderContents(HtmlTextWriter writer)
    {
    	if (Extender.AdapterEnabled)
    	{
    		GridView gridView = Control as GridView;
    		if (gridView != null)
    		{
    			if ((gridView.Rows.Count == 0) && !String.IsNullOrEmpty(gridView.EmptyDataText))
    			{
    				writer.WriteLine();
    				writer.WriteBeginTag("div");
    				writer.WriteAttribute("class", "AspNet-GridView-Empty");
    				writer.Write(HtmlTextWriter.TagRightChar);
    				writer.WriteLine();
    				writer.WriteLine(gridView.EmptyDataText);
    				writer.WriteEndTag("div");
    				return;
    			}
    
    Example of tag to be added to the css
     
    .NiceGridView .AspNet-GridView div.AspNet-GridView-Empty
    {
    	border-width: 1px;
    	border-style: solid;
    	border-color: #aaaaaa;
    	padding: 2px;
    }
    
     Cheers
     Joakim E. 
     
     
    Thursday, December 14, 2006 7:18 AM

All replies

  • User1725296223 posted

    Thank you for posting this solution.  I found it helpful and have used it.  The only thing I would add is that you can’t necessarily use the ‘EmptyDataTemplate.’  You have to configure the ‘EmptyDataText’ property for the gridview.  Obvious – I know, but I hope pointing it out saves others some time if needed.

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    Also, here’s the VB version:

    <o:p> </o:p>

                                        If (gridView.Rows.Count = 0) And Not String.IsNullOrEmpty(gridView.EmptyDataText) Then<o:p></o:p>

                                                    writer.WriteLine()<o:p></o:p>

                                                    writer.WriteBeginTag("div")<o:p></o:p>

                                                    writer.WriteAttribute("class", "AspNet-GridView-Empty")<o:p></o:p>

                                                    writer.Write(HtmlTextWriter.TagRightChar)<o:p></o:p>

                                                    writer.WriteLine()<o:p></o:p>

                                                    writer.WriteLine(gridView.EmptyDataText)<o:p></o:p>

                                                    writer.WriteEndTag("div")<o:p></o:p>

                                                    Return<o:p></o:p>

                                        End If

    Monday, January 1, 2007 5:13 PM
  • User266460057 posted

    I think I've got a fix for the EmptyDataTemplate issue:

     Add the following to RenderContents in GridViewAdapter.cs right before the ///// BODY //// section

      

    /////////////// EmptyDataTemplate ///////////////////////
    if (gridView.Rows.Count == 0) {
    	//Control[0].Control[0] s/b the EmptyDataTemplate.
    	if (gridView.HasControls()) {
    		if (gridView.Controls[0].HasControls()) {
    			if (gridView.Controls[0].Controls[0] is GridViewRow) {
    				rows.Clear();
    				rows.Add(gridView.Controls[0].Controls[0]);
    				gvrc = new GridViewRowCollection(rows);
    				WriteRows(writer, gridView, gvrc, "tfoot");
    			}
    		}
    	}
    }					
    

     

    Add the following to GetRowClass right before return className.Trim();

    //// EmptyDataTemplate
    if ((row.RowType & DataControlRowType.EmptyDataRow) == DataControlRowType.EmptyDataRow) {
    className += " AspNet-GridView-Empty ";
    }

     

    Finally, if you want to override the standard tfoot style, add a CSS section in GridViewExample -   

    .AspNet-GridView table tfoot tr.AspNet-GridView-Empty td
    {
        color: #F7F6F3;
        background: #5D7B9D;
        font-weight: bold;
        border-bottom: solid 1px #CCCCCC;
        border-right: solid 1px #CCCCCC;
        padding: 2px;
    }

    Hope this helps

    -Chris

    Thursday, January 4, 2007 12:53 PM
  • User2078398410 posted

    why am I getting the following:

    Error 6 'CompSoft.RenderContents(System.Web.UI.HtmlTextWriter)': no suitable method found to override I:\WebApps\ComputerLogging\CompSoft.aspx.cs 25 29 I:\WebApps\ComputerLogging\

    Stelly

    Tuesday, April 24, 2007 6:35 AM
  • User541223859 posted

    Since GridViews should be rendering tables - you can disable the ControlAdapter's Gridview render method.

    1.  Locate App_Browsers folder in your application.

    2.  Open CSSFriendlyAdapters.browser file.

    3.  Comment out the adapter that is responsible for rendering the GridView which is in the <controlAdapters> node.

    i.e comment out the following chunk..

    <adapter controlType="System.Web.UI.WebControls.GridView"
                   adapterType="CSSFriendly.GridViewAdapter" />

    4.  Now GridViews should be rendered as previously done by ASP.NET and not by CSSFriendly and you should see the EmptyDataTemplate displaying when there is no data available..




    Thursday, March 4, 2010 10:03 AM