Member 14631509 Ответов: 1

Как отобразить данные двух таблиц в одном datalist, выбрав изменение индекса в раскрывающемся списке в C#


<%@ 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)
    {
    }

   
   
}


Что я уже пробовал:

проблема в том, что данные одной таблицы различны, а данные второй таблицы, основанные на columnswise и формате, должны быть такими же, о которых я упоминал выше.