Hi Waghmare,
I have created a sample which full fill your requirement
HTML
<div align="center">
<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="false" DataKeyNames="EmpId"
OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="EmpId" HeaderText="Sr.No" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Designation" HeaderText="Designation" />
<asp:BoundField DataField="GroupName" HeaderText="GroupName" />
<asp:TemplateField HeaderText="Qualification">
<ItemTemplate>
<asp:GridView ID="gvQualification" ShowHeader="false" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="QualifictionDegree" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subject">
<ItemTemplate>
<asp:GridView ID="gvSubject" ShowHeader="false" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="SubjectName" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvEmployees.DataSource = GetData("SELECT EmpId,Name,Designation,GroupName FROM Employee");
gvEmployees.DataBind();
}
}
private static DataTable GetData(string query)
{
string strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = query;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string EmpId = gvEmployees.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvQualification = e.Row.FindControl("gvQualification") as GridView;
GridView gvSubject = e.Row.FindControl("gvSubject") as GridView;
gvQualification.DataSource = GetData(string.Format(@"SELECT Qualifiction.QualifictionDegree
FROM [QualEmpLinkTable]
INNER JOIN Employee
ON [QualEmpLinkTable].EmpId = Employee.EmpId
INNER JOIN Qualifiction
ON Qualifiction.QualId = [QualEmpLinkTable].QualID
WHERE Employee.EmpId ='{0}'", EmpId));
gvQualification.DataBind();
gvSubject.DataSource = GetData(string.Format(@"SELECT [Subject].SubjectName
FROM [QualEmpLinkTable]
INNER JOIN Employee
ON [QualEmpLinkTable].EmpId = Employee.EmpId
INNER JOIN [Subject]
ON [Subject].SubjectId = [QualEmpLinkTable].SubjectID
WHERE Employee.EmpId ='{0}'", EmpId));
gvSubject.DataBind();
}
}
ScreenShot