Hi santosh86,
I have created sample that full fill your requirement.
HTML
<div>
<asp:DataGrid ID="DataGrid1" runat="server" DataKeyNames="Id" BorderColor="White"
CellPadding="2" AutoGenerateColumns="False" Font-Names="Verdana" CssClass="table table-striped table-bordered table-hover">
<Columns>
<asp:BoundColumn DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundColumn DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundColumn DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
</Columns>
</asp:DataGrid>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = BindGrid();
if (dt.Rows.Count > 0)
{
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
}
else
{
dt.Rows.Add();
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
DataGrid1.Items[0].Visible = false;
}
}
}
private static DataTable BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(
new DataColumn[3]
{
new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string))
});
return dt;
}
OutPut