Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i have a gridview whose getting data from an database.i can do search and addition of data.but when u search for an record not present i ll display the message in a label present above d gridview.but my prob is..i need to display the header and footer(insertion through footers)
pls help me out...i need to do it soon
thanks
Posted
Updated 10-Jun-18 23:15pm

 
Share this answer
 
Comments
Member 8459400 6-Jan-12 3:00am    
its there a simple way of doing it then using datatable??
i m new to asp.net n i need to do this now..please help
It will Help u

C#
if (ds_login.Tables[0].Rows.Count == 0)
 {
     #region header with no record
     ds_login.Tables[0].Rows.Add(ds_login.Tables[0].NewRow());
     GridView1.DataSource = ds_login;
     GridView1.DataBind();
     int columncount = GridView1.Rows[0].Cells.Count;
     GridView1.Rows[0].Cells.Clear();
     GridView1.Rows[0].Cells.Add(new TableCell());
     GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
     GridView1.Rows[0].Cells[0].Text = "No Records Found";
     #endregion
 }
 else
 {
     GridView1.DataSource = ds_login;
     GridView1.DataBind();
 }
 
Share this answer
 
Comments
Venkatesh Chunchu 24-Jan-18 7:27am    
Working For Me Thanks.
Member 13745846 1-May-18 17:38pm    
That fixes the problem nicely.
you can do it by

C#
if (dt.Rows.Count > 0)
                {
                    grid1.DataSource = dt;
                    grid1.DataBind();
                }
                else
                {
                    dt.Rows.Add(dt.NewRow());
                    grid1.DataSource = dt;
                    grid1.DataBind();
                    int totalcolums = grid1.Rows[0].Cells.Count;
                    grid1.Rows[0].Cells.Clear();
                    grid1.Rows[0].Cells.Add(new TableCell());
                    grid1.Rows[0].Cells[0].ColumnSpan = totalcolums;
                    grid1.Rows[0].Cells[0].Text = "No Data Found";
                }
 
Share this answer
 
Comments
Member 8459400 6-Jan-12 2:57am    
grid1 represnts gridview id...wats dt??
devbtl 6-Jan-12 3:03am    
datatable dt=new datatable();
dt contain gridview data or simply a select query output for your gridview.
grid1 is your gridview
devbtl 6-Jan-12 3:16am    
new sqldataadaptor("select * from table").fill(dt);
then set this dt to gridview datasource
Member 8459400 6-Jan-12 3:38am    
can u suggest any other simple way of doing it
devbtl 6-Jan-12 3:41am    
try the abobe method if any error occured then plz let me know
may be you are not getting my point. see

first bind your gridview

if you are using datatable

then check the condition if (dt.rows.count>0) or (<0)
if it is > 0 then simply bind gridview. but in case if it is < 0. then in else statement try the below code

C#
dt.Rows.Add(dt.NewRow());
grid1.DataSource = dt;
grid1.DataBind();
int totalcolums = grid1.Rows[0].Cells.Count;
grid1.Rows[0].Cells.Clear();
grid1.Rows[0].Cells.Add(new TableCell());
grid1.Rows[0].Cells[0].ColumnSpan = totalcolums;
grid1.Rows[0].Cells[0].Text = "No Data Found";



if any error occured then let us know. Thanks
 
Share this answer
 
Comments
Member 8459400 6-Jan-12 4:44am    
dt.Rows.Add(dt.NewRow());
grid1.DataSource = dt;
grid1.DataBind();
int totalcolums = grid1.Rows[0].Cells.Count; //i m getting a arguementoutofrange exception here
grid1.Rows[0].Cells.Clear();
grid1.Rows[0].Cells.Add(new TableCell());
grid1.Rows[0].Cells[0].ColumnSpan = totalcolums;
grid1.Rows[0].Cells[0].Text = "No Data Found";


pls help me...i m in trouble or else
dhanabalaan 13-Feb-14 2:07am    
Its working fine in first time load, but after postback colspan not working.
you can use emptydatatemplate to display some thing when the gridview is empty

try this
========
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatemplate.aspx
 
Share this answer
 
try this
<asp:gridview id="gvwPlanDetail" autogeneratecolumns="false" runat="server" width="100%" xmlns:asp="#unknown">
                        OnRowDataBound="gvwPlanDetail_RowDataBound">
                        <emptydatarowstyle />
                        <emptydatatemplate>
                            <td>
                                Created Date
                            </td>
                            <td>
                                Modified Date
                            </td>
                            <td>
                                App Status
                            </td>
                        </emptydatatemplate>
                        <columns>


                            <asp:templatefield headertext=" Created Date">
                                <itemtemplate>
                                    <asp:label id="lblCreatedDate" runat="server" text="<%#DataBinder.Eval(Container.DataItem,"CreatedDate") %>"></asp:label>
                                </itemtemplate>
                            </asp:templatefield>
                            <asp:templatefield headertext="Modified Date">
                                <itemtemplate>
                                    <asp:label id="lblModifiedDate" runat="server" text="<%#DataBinder.Eval(Container.DataItem,"ModifiedDate") %>"></asp:label>
                                </itemtemplate>
                            </asp:templatefield>
                            <asp:templatefield headertext="APP Status">
                                <itemtemplate>
                                    <asp:label id="lblStatus" visible="true" runat="server" text="<%#DataBinder.Eval(Container.DataItem,"AppStatus")%>">
                                    </asp:label>
                                     <asp:imagebutton id="ibtnCancel" runat="server" imageurl="~/images/Cancel_New.gif">
                                      ToolTip="Cancel Scheme" CssClass="groovybutton"
                                                    Visible="false" OnCommand="ibtnCancel_Command" OnClientClick="return confirm('Are you sure you want to Cancel Plan?')"/>
                                  </asp:imagebutton></itemtemplate>
                            </asp:templatefield>
                        </columns>
                    </asp:gridview>
 
Share this answer
 

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