Hello friend, I'm trying to provide a solution as far as I understood the requirement. I believe apart from
tbl_Lecturer and
tbl_Student tables, you have introduced a third table to hold the one-to-many relationship. Let's say the new table name is
tbl_Lecturer_Student.
I also assume that one Lecturer can be selected at a time hence
ListBox
control would be better choice than a
CheckBoxList
control for Lecturer.
CheckBoxList
is fine for Students.
Last assumption and not the least, this UI would be used for Saveing relationship among Lecturer and Students.
Here we go:
<table style="width: 50%;" border="1">
<tr>
<th>Lecturer:</th>
<th>Student:</th>
</tr>
<tr>
<td>
<asp:Panel runat="server" ScrollBars="Vertical" Height="150px">
<asp:ListBox ID="lstLecturer" runat="server" Width="100%">
<asp:ListItem Value="1">Lecturer1</asp:ListItem>
<asp:ListItem Value="2">Lecturer2</asp:ListItem>
<asp:ListItem Value="3">Lecturer3</asp:ListItem>
<asp:ListItem Value="4">Lecturer4</asp:ListItem>
<asp:ListItem Value="5">Lecturer5</asp:ListItem>
<asp:ListItem Value="6">Lecturer6</asp:ListItem>
</asp:ListBox>
</asp:Panel>
</td>
<td style="height: 100px;">
<asp:Panel runat="server" ScrollBars="Vertical" Height="150px">
<asp:CheckBoxList ID="cblStudent" runat="server" Width="100%">
<asp:ListItem Value="1">Student-1</asp:ListItem>
<asp:ListItem Value="2">Student-2</asp:ListItem>
<asp:ListItem Value="3">Student-3</asp:ListItem>
<asp:ListItem Value="4">Student-4</asp:ListItem>
<asp:ListItem Value="5">Student-5</asp:ListItem>
<asp:ListItem Value="6">Student-6</asp:ListItem>
<asp:ListItem Value="7">Student-7</asp:ListItem>
<asp:ListItem Value="8">Student-8</asp:ListItem>
<asp:ListItem Value="9">Student-9</asp:ListItem>
<asp:ListItem Value="10">Student-10</asp:ListItem>
</asp:CheckBoxList>
</asp:Panel>
</td>
</tr>
</table>
<p>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
</p
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (ListItem lecturer in lstLecturer.Items)
{
if (lecturer.Selected == true)
{
foreach (ListItem student in cblStudent.Items)
{
if (student.Selected == true)
{
}
}
break;
}
}
}
Let me know if you have any further query. I'll be happy to help you :)