Page Source View:-
i have taken one Panel and and two gridView .Here is the source code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView Within GridView.aspx.cs" Inherits="GridView_Within_GridView" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<span>
<asp:Panel ID="Panel7" runat="server" Height="250px"
Width="920px" ScrollBars="Vertical" Visible="false">
<asp:GridView ID="GdviewParent" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" Width="900px" >
<PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next"
PreviousPageText="Prev" />
<FooterStyle BackColor="#009933" ForeColor="#003399" />
<RowStyle BackColor="White" ForeColor="#003399" />
<Columns>
<asp:TemplateField HeaderText="Asp:GridView" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text="Date:"></asp:Label>
<%#Eval("Date")%>
<asp:Label ID="Label3" runat="server" Text="Guest Name:"></asp:Label>
<asp:Label ID="Label8" runat="server" Text='<%#Eval("GstName")%>'></asp:Label>
<br />
<asp:Label ID="Label9" runat="server" Text="Bill No:"></asp:Label>
<asp:Label ID="Label10" runat="server" Text='<%#Eval("BillNO")%>'></asp:Label>
<asp:Label ID="Label1" runat="server" Text="RoomNo:"></asp:Label>
<%#Eval("RoomNo")%><br />
<asp:Label ID="Label2" runat="server" Text="ChalanN0 No:"></asp:Label>
<asp:Label ID="Label11" runat="server" Text='<%#Eval("ChalanN0")%>'></asp:Label>
<br />
<%--Here i Have Bind the child GridView:- --%>
<asp:GridView ID="GridViewChild" runat="server" AutoGenerateColumns="false"
DataSource='<%#blcommon.getData(Eval("ChalanN0")) %>' Width="880px">
<Columns>
<asp:TemplateField HeaderText="Sl.No" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblSlno" runat="server" Text="<%#Container.DataItemIndex+1 %>" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Name" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Eval("Item")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quatity" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Eval("Quantity")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rate" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Eval("Rate")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Eval("Tax")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Eval("Amount")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#009900" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#009933" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#009933" ForeColor="Black"/>
</asp:GridView>
</asp:Panel>
</span>
<div>
</div>
</form>
</body>
</html>
Take one button id as button1 and here is button1 click events:-
protected void button1_Click(object sender, EventArgs e)
{
BindGrid();
}
public void BindGrid()
{//i have bind data from date to toDate and i have used some 3 tire architecture to bind that Parent gridview you can bind this Parent Gridview as in Your comfortable way of coding
if (TxtFrmDate.Text != "" || TxtToDate.Text != "")
{
HouseBO hBO = new HouseBO();
DataSet DS = null;
hBO.Operation = "SelectLndryChlBil";
hBO.Date4 = TxtFrmLundryReport.Text;
hBO.Date5 = TxtTolndryRprt.Text;
DS = hBO.SelectLndryChlBil(hBO);
if (DS.Tables.Count > 0)
{
GdViewLndryRprt.DataSource = DS.Tables[0];
GdViewLndryRprt.DataBind();
if (DS.Tables[0].Rows.Count > 7)
{
Panel7.Visible = true;
Panel7.ScrollBars = ScrollBars.Vertical;
Panel7.Height = 250;
}
else
{
Panel7.Visible = true;
Panel7.ScrollBars = ScrollBars.Auto;
Panel7.Height = GdviewParent.Height;
}
}
}
else
{
HouseBO hBO = new HouseBO();
DataSet DS = null;
hBO.Operation = "SelectLndryChlBil1";
DS = hBO.SelectLndryChlBil1(hBO);
if (DS.Tables.Count > 0)
{
GdviewParent.DataSource = DS.Tables[0];
GdviewParent.DataBind();
if (DS.Tables[0].Rows.Count > 7)
{
Panel7.Visible = true;
Panel7.ScrollBars = ScrollBars.Vertical;
Panel7.Height = 250;
}
else
{
Panel7.Visible = true;
Panel7.ScrollBars = ScrollBars.Auto;
Panel7.Height = GdviewParent.Height;
}
}
}
}
using System;
using System.Data;
using System.Configuration;
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;
using System.Data.SqlClient;
/// <summary>
/// Summary description for utility
/// </summary>
public class utility
{
static string ConnString = ConfigurationManager.ConnectionStrings["cs"].ToString();
public utility()
{
//
// TODO: Add constructor logic here
//
}
public static DataSet GetData(string sqlstat)
{
SqlConnection cn = new SqlConnection(ConnString);
SqlDataAdapter da = new SqlDataAdapter(sqlstat, cn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
} }
This is my blcommon Class Which is derived in a specific folder like App Code
using System;
using System.Data;
using System.Configuration;
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;
/// <summary>
/// Summary description for blcommon
/// </summary>
public class blcommon
{
public blcommon()
{
//
// TODO: Add constructor logic here
//
}
public static DataSet getData(object s)
{
string ChalanN0 = s.ToString();
return utility.GetData("select * from LaunderyChalana L where L.ChalanN0=" + ChalanN0);
}
}
No comments:
Post a Comment
Please don't spam, spam comments is not allowed here.