What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 595 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Nested gridview example ...
Santosh0683

Nested gridview example

 Code Snippet posted by: Santosh0683 | Posted on: 7/23/2010 | Category: ASP.NET Codes | Views: 6908 | Status: [Member] | Alert Moderator   


<asp:GridView ID="GridView2" runat="server" EnableTheming="False" PageSize="25" Width="900px"

OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound"
meta:resourcekey="GridView1Resource1" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Employee Loan Balance Details">
<ItemTemplate>
<table>
<tr>
<td>
Company</td>
<td>
:</td>
<td colspan="4">
<asp:Label ID="lblCompany" runat="server" Text='<%# Bind("Company") %>'></asp:Label></td>
</tr>
<tr>
<td>
Date</td>
<td>
:</td>
<td colspan="4">
<asp:Label ID="lblDate" runat="server"></asp:Label></td>
</tr>
<tr>
<td colspan="6">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" EnableTheming="False"
PageSize="20" Width="100%" OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDataBound="GridView1_RowDataBound" meta:resourcekey="GridView1Resource1"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="User Name" HeaderText="Name">
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="LoanName" HeaderText="Loan">
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Show Name" HeaderText="Payroll Month">
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="PDate" HeaderText="Paid Date">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="OpeningBalance" HeaderText="Open Date">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="PaidAmount" HeaderText="Amt. Paid">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
</Columns>
<RowStyle CssClass="reporttext" />
<EmptyDataTemplate>
<strong><span style="font-size: 10pt;">No Records....!</span> </strong>
</EmptyDataTemplate>
<PagerStyle CssClass="reportheader" />
<HeaderStyle CssClass="reportheader" Width="80px" />
<AlternatingRowStyle CssClass="reporttext" />
</asp:GridView>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



protected void FirstGridBind()
{
DataTable dt1DataTable = new DataTable();
dt1.Columns.Add("CompanyName");
DataRow drDataRow = dt1DataTable.NewRow();
if (ddlCompany.SelectedValue != "0")
{
drDataRow["CompanyName"] = ddlCompany.SelectedItem.Text;
}
else
{
drDataRow["CompanyName"] = "All Companies";
}

dt1DataTable.Rows.Add(drDataRow);
GridView2.DataSource = dt1DataTable;
GridView2.DataBind();
}

protected void SecondGridBind()
{
foreach (GridViewRow row in GridView2.Rows)
{
Label lblDate = row.FindControl("lblDate") as Label;
if (txtFromDate.Text.Trim() != "" && txtToDate.Text.Trim() != "")
{
lblDate.Text = txtFromDate.Text.Trim() + " - " + txtToDate.Text.Trim();
}
else
{
lblDate.Text = "All Dates";
}
GridView GridView1 = row.FindControl("GridView1") as GridView;

string str = @"SELECT You query;

if (ddlCompany.SelectedValue != "0")
{
str += " AND (hrdEmployeeMaster.CompanyId = " + Convert.ToInt32(ddlCompany.SelectedValue) + ")";
}

DataTable dt = SqlHelper.ExecuteDataset(connString, CommandType.Text, str).Tables[0];
Session["myDataTable"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
if (GridView1.Rows.Count > 0)
{
lbExport.Visible = true;

}
}
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (GridView2.Rows.Count > 0)
{
GridView GridView1 = GridView2.Rows[0].FindControl("GridView1") as GridView;

e.Row.Cells[0].Text = Convert.ToString(GridView1.PageIndex * GridView1.PageSize + SrNo);
SrNo++;
}
}
}


Santosh Singh
http://aspdotnetcode.blogspot.in/
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 11:32:06 PM