Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 11767 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > C# > SIMPLE NESTED GRID IN ASP.NET ...
K011gusain89

SIMPLE NESTED GRID IN ASP.NET

 Code Snippet posted by: K011gusain89 | Posted on: 10/22/2012 | Category: C# Codes | Views: 428 | Status: [Member] | Points: 40 | Alert Moderator   
Ads

Source Code


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript" >
function ol(divId) {
var ok = divId;
var ok2 = "DivID" + ok;
$("#"+ ok2).slideToggle();
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="Gv1" runat="server" onrowdatabound="Gv1_RowDataBound" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField>
<ItemTemplate>

<asp:LinkButton ID="btnlink" runat="server" Text='<%#Eval("course_name")%>' OnClientClick='<%# "javascript:ol("+Eval("course_id")+");return false;" %>'></asp:LinkButton>

<div id='DivID<%#Eval("course_id")%>'>
<asp:GridView ID="Gv2" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField><ItemTemplate><%#Eval("session")%></ItemTemplate></asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>





C# Code



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace Nested_Grid_View
{
public partial class Nested_Page : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"server=LOCAL-PC;database=DATABASE_NAME;integrated security=true");

protected void Page_Load(object sender, EventArgs e)
{

SqlCommand com = new SqlCommand("select * from tb_course",con);

con.Open();
DataTable dt = new DataTable();
dt.Load(com.ExecuteReader());

Gv1.DataSource = dt;
Gv1.DataBind();



}

protected void Gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{


if (e.Row.RowType == DataControlRowType.DataRow)
{

GridView ok = e.Row.FindControl("Gv2") as GridView;


if (ok != null)
{
SqlCommand com = new SqlCommand("select * from tb_session",con);
con.Close();
con.Open();
ok.DataSource = com.ExecuteReader();
ok.DataBind();
con.Close();

}

else
{


}
}


}
}
}
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. | 6/20/2013 1:57:07 AM