Hello guys,
I need help here. I´m new to C# and asp.net, i'm doing a program that shows a list box with the users in the DB. A user has a group or a schedule.
What i want to do is, when the user selects a user i want to show in another listbox(ListBox1) the group or schedule he is in.
My problem is in comparing the id i receive from the listbox to the relations in groups or schedules and show them in the listbox.
Any help? The code is above.
DB: in attatchement
<td>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="listusers" runat="server" DataSourceID="LinqDataSource1"
DataTextField="userName" DataValueField="id" OnSelectedIndexChanged="userdetails"></asp:ListBox>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="UserAccessSchedulerv4.UserAccessSchedulerEntities"
Select="new (id, userName)" TableName="User">
</asp:LinqDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server">
</asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
----------
UserAccessSchedulerEntities context = new UserAccessSchedulerEntities();
UserGroupRelation ugr = new UserGroupRelation();
public void userdetails(object sender, EventArgs e)
{
long userId = Convert.ToInt64(listusers.DataValueField);
User selectedUser = (from g in context.User
where g.id == userId
select g.id).First();
IEnumerable<UserGroupRelation> relations = from r in context.UserGroupRelation
where r.User.id == selectedUser.id
select r;
foreach (UserGroupRelation ugr in relations)
{
}
}