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


        }

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


        }

I have used something like the following to do similar things.

List<ScheduleObject> scheduleList = new List<ScheduleObject>();
List<GroupObjec> groupList = new List<GroupObject>();

IQueryable<User> user = context.User.Include("UserGroupRelation.Group").Include("Schedule").Where(u => i.id == userId );

foreach (User u in user)
{
    ScheduleObject schedule = new ScheduleObject(); 
   // A business object that might encapsulate a Schedule entity;
   //     beware circular references.
   GroupObject group = new GroupObject();
   // A business object that might encapsulate a Group entity;
   //     beware circular references.


    // Populate properties in schedule and group, there are several
    //  ways to do this.

   scheduleList.Add(schedule);
   groupList.Add(group);
}

// Set data source in ListBox1 appropriately.

I hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.