Search code examples
asp.net-mvc-3webgrid

Custom message inside the webgrid if empty Using Asp.net Mvc3?


I would like to display a message "No Records are Not Found" inside the web grid in the else statement below. Can someone help me with this?

<%      
var grid = new WebGrid(source: Model, defaultSort: "ProjectName", rowsPerPage: 5);
using (Html.BeginForm())
{ %> 
    <div class="resourcereprtsmain">
    <%:Html.Label("Project Name") %>
    <%: Html.DropDownList("Projects", (SelectList)ViewBag.Projects, "--Select Project--")%>   
    <br />
    <%:Html.Label("Release Phase") %>
    <%:Html.DropDownList("ReleasePhase", "--Select ReleasePhase--")%>                                      

    <input type="submit" value="search" />                            
    </div>                                                                  
    <div id="grid">
    <%:grid.GetHtml(
     tableStyle: "listing-border_c", headerStyle: "gridhead", footerStyle: "paging", rowStyle: "td-dark", alternatingRowStyle: "td-light",                            
     columns:grid.Columns(
     grid.Column("ProjectName", "Project Name"),
     grid.Column("ReleasePhase", "ReleasePhase"),
     grid.Column("Newbugs", "New Bugs"),
     grid.Column("Assignedbugs", "Assigned Bugs"),
     grid.Column("Fixedbugs", "Fixed Bugs"),
     grid.Column("Reopenedbugs", "Reopened Bugs"),
     grid.Column("Closedbugs", "Closed Bugs"),
     grid.Column("Defferedbugs", "Deffered Bugs"),
     grid.Column("NotaBug", "Not a Bug")                           
      ))%>
    </div>                  
<%} %>

Solution

  • In Controller code

          if (ds.Tables[0].Rows.Count == 0)
                {
    
                    TempData["notice"] = "No Records are Not Found";
    
                }
                else
                {
    
                }
    

    In View code

    <% if (TempData["notice"] != null) { %>
    <p><label id="msgtext" >No Records Are Not found !!!!</label></p>
     <% } %>
    

    I got Answer