Show message on my webpage
how i can show msg on my webpage if there is no record show in a gridview
i take many hyperlink button on my webpage and according to that data is shown in a gridview and the record is not matching gridview not appear at that time i want a msg in the webpage. please help me as soon as possible!!!
Re: Show message on my webpage
You can check the DataSource of the GridView if it is empty then show the message to the user.
Re: Show message on my webpage
If there is no data to disply, the following code will show the message "No records found" in webpage.
<table style="width: 100%; height:90%" border="0">
<tr style="width: 100%; height:300px" valign="top">
<td>
<asp:GridView ID="gvApplicants" runat="server" AutoGenerateColumns="False"
CellPadding="1" ForeColor="#333333"
GridLines="None" Width="100%" FooterStyle-HorizontalAlign="Left"
PagerStyle-HorizontalAlign="Left" PageSize="13" AllowPaging="True" OnRowDataBound="gvApplicants_RowDataBound" OnDataBound="gvApplicants_DataBound" OnRowEditing="gvApplicants_RowEditing" OnRowCancelingEdit="gvApplicants_RowCancelingEdit" >
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" CssClass="GridView" />
<RowStyle BackColor="#EFF3FB" CssClass="GridView" />
<SelectedRowStyle Font-Bold="True" ForeColor="#333333" Font-Size="Small" BackColor="#8080FF" BorderColor="#8080FF" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" Font-Size="Small" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" CssClass="GridView" />
<AlternatingRowStyle BackColor="White" />
<EmptyDataTemplate>
No records found
</EmptyDataTemplate>
<PagerTemplate>
</PagerTemplate>
<Columns>
<asp:BoundField Visible="false" DataField="pers_no" />
<asp:TemplateField HeaderText="Applicant Number" HeaderStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="lblAppNo" runat="server" Width="36%" CssClass="Label" Text='<%#Eval("empno")%>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Right" />
<ItemStyle width= "7%" />
</asp:TemplateField>
<asp:BoundField>
<ItemStyle Width="2%" />
<HeaderStyle Width="2%" />
</asp:BoundField>
<asp:TemplateField HeaderText="Name" HeaderStyle-VerticalAlign="top">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Width="100%" CssClass="Label" Text='<%#Server.HtmlEncode((string)Eval("name"))%>'></asp:Label>
</ItemTemplate>
<ItemStyle />
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr style="border:1px">
</tr>
</table>
Re: Show message on my webpage
Hi Nidhi,
As per your quote it seems that u are populating grid with AutoGenerate columns property true.
In this case u need to add EmptyDataTemplate to grid through code and put your message within it.
In other case, u can right click on grid, go to Edit Template and click on EmptyDataTemplate. Type your message within area provided.
Hope this would help u.
---V V---
Vikas Vaidya
Re: Show message on my webpage
There is simple solution for that in code check for Gridview contains, If the fridview contains no rows the do the response.write("your custom message");
To check gridview contain no rows -> gridview object.rows.count==0 then response.write("");
Re: Show message on my webpage
if(GridView1.Rows.Count==0)
{
//display your msg here.
}
thats it!
Re: Show message on my webpage
SO SIMPLE DEAR,
if there is record then its okay.
but if there is not records comming to gridview then just make sure that gridview doesn't have any record by a small coding//
That is,
GridView1.DataBind();
if (GridView1.Rows.Count ==0)
{
Label1.Text = "no such employee exits";
}
else { }
it will first see that there is no data found so it will display that message...
okay...
for detail pls meet me at [email]engg_nyks@yahoo.co.in[/email]
bye
Re: Show message on my webpage
you can give messge in emptydatatemplate as follow
clik on the arrow on the top of the gridview control,click on edit template option and now select the emptyDataTemplate and write the message there
Re: Show message on my webpage
Hi,
Hope you are databinding gridview with some data source.
Go to gridview properties and set EmptyDataText="Record not found".
Hope this will help you. :)
Thanks,
Re: Show message on my webpage
Hi,
Below is the code for showing the message where the grid retrieves no data :
Here i have taken one lable to show the message.
Dim con as new sqlconnection(str) ''here str is the connection string
dim sql as string
dim count as integer
con.open()
sql ="select id,name,mailid from emp"
dim da as new sqldataadapter(sql ,con)
dim ds as new dataset
da.fill(ds,"emp")
gridview1.datasource=ds.tables(0)
if ds.tables(0).rows.count<1 then
lable1.text="No Records found"
else
lable1.visible=false
end if
gridview1.databind()
con.close()
Happy coding,
Ramesh....
Re: Show message on my webpage
[QUOTE=nidhi.amulya;29329]how i can show msg on my webpage if there is no record show in a gridview
i take many hyperlink button on my webpage and according to that data is shown in a gridview and the record is not matching gridview not appear at that time i want a msg in the webpage. please help me as soon as possible!!![/QUOTE]
ans:
go 2 gridview then select Edit temples you will get a box over there then write your message there .