Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FinalStudentDetail.aspx.cs" Inherits="FinalStudentDetail" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <th colspan="3">Achievement Records</th>
                </tr>
                <tr>
                    <td>Select Student</td>
                    <td>:</td>
                    <td>
                        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList>

                    </td>
                </tr>
                
            </table>
           
             <asp:DataList ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand" OnItemDataBound="DataList1_ItemDataBound">
                 <ItemTemplate>
                     <table border="1">
                         <tr>
                             <td colspan="2">

                                 <asp:Label ID="lb_id" Text='<%#Eval("exmNam") %>' runat="server" />
                             </td>
                         </tr>
                         
                
                
                       <tr>
                             <td><%# Eval("scrSubName") %></td>
                             <td><%# Eval("scrAch") %></td>
                         </tr>
                         </table>
                 </ItemTemplate>
                 <AlternatingItemTemplate>
                     <table border="1">
                         <tr>
                             <td colspan="2">
                                 <asp:Label ID="lb_id" Text='<%#Eval("exmNam") %>' runat="server" />
                             </td>
                         </tr>
                         <tr>
                             <th>Subject Name</th>
                             <th>Achievement</th>
                         </tr>
                
                
                       <tr>
                             <td><%# Eval("scrSubName") %></td>
                             <td><%# Eval("scrAch") %></td>
                         </tr>
                         </table>
                 </AlternatingItemTemplate>
                 <FooterTemplate>
                     </table>
                 </FooterTemplate>
             </asp:DataList>
        </div>
    </form>
</body>
</html>



<pre>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;
using System.Configuration;

public partial class FinalStudentDetail : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
            Response.Write(@"<script language='javascript'>alert('Connection is open')</script>");
        }
        if (Page.IsPostBack == false)
        {
            DropDownList1_Bind();
            
        }

    }
    public void DropDownList1_Bind()
    {
        SqlCommand cmd = new SqlCommand("select * from tbStu", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        DropDownList1.DataValueField = "stuCod";
        DropDownList1.DataTextField = "stuNam";
        DropDownList1.DataSource = sdr;

        DropDownList1.DataBind();
        DropDownList1.Items.Insert(0, "Select Student");
        sdr.Close();
        cmd.Dispose();

    }
    
    public void DataList_Bind()
    {
       String query;
        query= "select distinct exmNam from tbExm;select stuNam, exmNam,scrSubName,scrAch from tbScr,tbStu,tbExm where scrStuCod=stuCod and scrExmCod=exmCod and stuCod=@Cod";
      
        SqlDataAdapter sda = new SqlDataAdapter(query,con);
        sda.SelectCommand.Parameters.AddWithValue("@Cod", DropDownList1.SelectedValue);
        DataSet ds = new DataSet();
        sda.Fill(ds);

        DataList1.DataSource = ds;
        DataList1.DataBind();
       
       
    }
    
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
     
        DataList_Bind();
    }

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
    }

   
   
}


What I have tried:

problem is one table data is distinct and second table data based on columnswise and format should be same which i have mentioned above.
Posted
Updated 4-Nov-19 1:04am
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900