TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
arun kumar
NA
18
21.8k
Empty will be dispalyed if there is no data in grid
Feb 22 2013 2:26 AM
<table border="0" cellpadding="0" cellspacing="0">
<ajax:UpdatePanel ID="upd1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="grdView" runat="server" AutoGenerateColumns="False" CellPadding="0"
ShowFooter="True" BorderWidth="1px" BorderColor="#D1D7E3" OnPageIndexChanging="grdView_PageIndexChanging"
OnRowCancelingEdit="grdView_RowCancelingEdit" OnRowEditing="grdView_RowEditing"
OnRowUpdating="grdView_RowUpdating" OnRowDeleting="grdView_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="TrigID" Visible="False">
<ItemTemplate>
<asp:Label ID="lblTrigID" runat="server" Text='<%# Eval("TrigID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CustodianID" Visible="False">
<ItemTemplate>
<asp:Label ID="lblCustodianID" runat="server" Text='<%# Eval("CustodianID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TrgFileName">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "TrgFileName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTrgFileName" runat="server" Height="11px" Width="110px" Font-Size="XX-Small"
Text='<%# Eval("TrgFileName") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqflName" runat="server" ControlToValidate="txtTrgFileName" ValidationGroup="Existing" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTrgFileName" runat="server" Height="11px" Width="110px"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqTrgFleNm" runat="server" ControlToValidate="txtTrgFileName" ValidationGroup="Footer" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TrgFilePath">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "TrgFilePath")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTrgFilePath" runat="server" Height="11px" Width="110px" Font-Size="XX-Small"
Text='<%# Eval("TrgFilePath") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqflPath" runat="server" ControlToValidate="txtTrgFilePath" ValidationGroup="Existing" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTrgFilePath" runat="server" Height="11px" Width="110px"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqTrgFlePt" runat="server" ControlToValidate="txtTrgFilePath" ValidationGroup="Footer" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ChkExistence" ItemStyle-HorizontalAlign="Center">
<EditItemTemplate>
<asp:CheckBox ID="ChkExistence" runat="server" Checked='<%# bool.Parse(Eval("ChkExistence").ToString() == "True" ? "True": "False") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="ChkExistence" runat="server" Checked='<%# bool.Parse(Eval("ChkExistence").ToString() == "True" ? "True": "False") %>'
Enabled="False" />
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="ChkExistence" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CreateTrgFile" ItemStyle-HorizontalAlign="Center">
<EditItemTemplate>
<asp:CheckBox ID="ChkCreateTrgFile" runat="server" Checked='<%# bool.Parse(Eval("CreateTrgFile").ToString() == "True" ? "True": "False") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="ChkCreateTrgFile" runat="server" Checked='<%# bool.Parse(Eval("CreateTrgFile").ToString() == "True" ? "True": "False") %>'
Enabled="False" />
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="ChkCreateTrgFile" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RemoveFile" ItemStyle-HorizontalAlign="Center">
<EditItemTemplate>
<asp:CheckBox ID="ChkRemoveFile" runat="server" Checked='<%# bool.Parse(Eval("RemoveFile").ToString() == "True" ? "True": "False") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="ChkRemoveFile" runat="server" Checked='<%# bool.Parse(Eval("RemoveFile").ToString() == "True" ? "True": "False") %>'
Enabled="False" />
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="ChkRemoveFile" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" HeaderStyle-Width="230px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<span style="margin: 0 0 0 45px;">
<asp:ImageButton ID="imgEdit" runat="server" Height="20px" ToolTip="Edit" AlternateText="Edit"
CommandName="Edit" ImageUrl="images/icon_edit.png" />
<asp:ImageButton ID="imgDelete" runat="server" Height="20px" ToolTip="Delete" AlternateText="Delete"
CommandName="Delete" ImageUrl="images/icon_delete.png" /></span>
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ID="imgUpdate" runat="server" Height="20px" ToolTip="Edit" AlternateText="Edit"
CommandName="Update" ValidationGroup="Existing" ImageUrl="images/Update-Icon.jpg" />
<asp:ImageButton ID="imgCancel" runat="server" Height="20px" ToolTip="Cancel" AlternateText="Cancel"
CommandName="Cancel" ImageUrl="images/Cancel-Icon.jpg" /></span>
</EditItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="imgAdd" runat="server" Height="20px" ToolTip="Add" CommandArgument="Add"
ImageUrl="images/icon_add.png" OnClick="imgAdd_Click" ValidationGroup="Footer" />
</FooterTemplate>
<HeaderStyle Width="230px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="mainHead" />
<EditRowStyle HorizontalAlign="Center" />
<AlternatingRowStyle CssClass="evenRow" />
<FooterStyle CssClass="inputField" HorizontalAlign="Center" Height="30px" />
</asp:GridView>
</ContentTemplate>
</ajax:UpdatePanel>
</table>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace NAMe
{
public partial class Details : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
//Show Empty Data Grid With Header and Footer When DataTable or Dataset is NULL
this.ShowEmptyGrid(grdView);
if (!Page.IsPostBack)
{
}
}
}
protected void poulategrid(string val)
{
DataTable dt =
grdView.DataSource =
grdView.DataBind();
//Show Empty Data Grid With Header and Footer When DataTable or Dataset is NULL
this.ShowEmptyGrid(grdView);
}
//Show Empty Data Grid With Header and Footer When DataTable or Dataset is NULL
protected void ShowEmptyGrid(GridView grdView)
{
// Executes After Grid Load Method
if (grdView.Rows.Count == 0 &&
grdView.DataSource != null)
{
DataTable dt = null;
//We have To clone the Sources
if (grdView.DataSource is DataSet)
{
dt = ((DataSet)grdView.DataSource).Tables[0].Clone();
}
else if (grdView.DataSource is DataTable)
{
dt = ((DataTable)grdView.DataSource).Clone();
}
if (dt == null)
{
return;
}
//Adding Empty Row
dt.Rows.Add(dt.NewRow());
grdView.DataSource = dt;
grdView.DataBind();
//Hiding The Row
grdView.Rows[0].Visible = false;
grdView.Rows[0].Controls.Clear();
}
}
}
}
Reply
Answers (
1
)
Unable to cast object ?
restart