A Column is not being displayed for two specific roles. RRS feed

  • Question

  • User1929428035 posted

    The table under scrutiny is the HomeWork table:

    Table        : Columns

    HomeWork: ID, ClassID, SubjectID, HomeWorkDetails, DateHWGiven, DueDate.

    The ClassID column is not being displayed for the roles Student and Parent.

    Here is the code:

    [RequiresRole("Clerk", "Teacher", "Principal", "Student", "Parent")]
    public IQueryable<HomeWork> GetHomeWork()
         if (this.ServiceContext.User.IsInRole("Student"))
              int intClassID = getClassIDByStudent();
    	  return this.ObjectContext.HomeWork.Include("Class").Include("Subject").Where(s => s.ClassID == intClass                ID).OrderByDescending(s => s.ID);
         if (this.ServiceContext.User.IsInRole("Parent"))
              List<int> intListofStudentIDs = new List<int>();
    	  intListofStudentIDs = getStudentIDsByParent(getParentID());
    	  List<int> intListofClassIDs = getClassIDByStudents(intListofStudentIDs);
    	  return this.ObjectContext.HomeWork.Include("Class").Include("Subject").Where(s => intListofClassIDs.Any                (i => i == s.ClassID)).OrderByDescending(h => h.ID);
          return this.ObjectContext.HomeWork.Include("Class").Include("Subject").OrderByDescending(h => h.ID);

    Please tell me what is the problem.

    Tuesday, July 30, 2013 3:56 AM

All replies

  • User-665789584 posted

    What do you mean by 'The ClassID column is not being displayed'? Is it not returning any value or is it not displaying in a grid or some other control? Did you try to step through the code and see if it is returing any value?

    Tuesday, July 30, 2013 10:06 AM
  • User1929428035 posted

    The name of the class is not being displayed in the gridview:

    Tuesday, July 30, 2013 10:15 AM
  • User-665789584 posted

    Can you post the markup for the grid and the code that you use to bind the grid.

    Tuesday, July 30, 2013 10:19 AM
  • User1929428035 posted

    This is a Dynamic Data project to which I am relative new to so I do not know where exactly the data binding is taking place. However here is the markup:

    <%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="List.aspx.cs" Inherits="sims.List" %>
    <%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>
    <asp:Content ID="headContent" ContentPlaceHolderID="head" Runat="Server">
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <div style="; top:150px; left: 120px;">
        <h2 style="font-family: Arial; font-size: medium; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none"><a id="A1" runat="server" href="~/Default.aspx">Back to List of Options</a></h2>
        <br />
        <div style="; top:250px; left:120px;">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <div class="DD">
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                        HeaderText="List of validation errors" CssClass="DDValidator" />
                    <asp:DomainValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" CssClass="DDValidator" />
                    <asp:QueryableFilterRepeater runat="server" ID="FilterRepeater">
                            <asp:Label runat="server" Text='<%# Eval("DisplayName") %>' OnPreRender="Label_PreRender" />
                            <asp:DynamicFilter runat="server" ID="DynamicFilter" OnFilterChanged="DynamicFilter_FilterChanged" /><br />
                     <asp:Button ID="searchButton" runat="server" OnClick="SearchButton_Click" 
    				  Text="Get List By Date" />
                    <br />
    		  <br />
    		  <h1 style="font-family:Ariel; font-size:large" class="DDSubHeader"><%= table.DisplayName%></h1>
    		  <div class="DDBottomHyperLink">
                    <asp:DynamicHyperLink ID="InsertHyperLink" runat="server" Action="Insert"><img id="Img2" runat="server" src="~/DynamicData/Content/Images/plus.gif" alt="Insert new item" />Insert new item</asp:DynamicHyperLink>
                <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true"
                    AllowPaging="True" AllowSorting="True" CssClass="DDGridView"
                    RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6">
                                <asp:DynamicHyperLink runat="server" Action="Edit" Text="Edit" Visible='<%# table.CanUpdate(User) %>'
                                />&nbsp;<asp:LinkButton runat="server" CommandName="Delete" Text="Delete" Visible='<%# table.CanDelete(User) %>'
                                    OnClientClick='return confirm("Are you sure you want to delete this item?");'
                                />&nbsp;<asp:DynamicHyperLink runat="server" Text="Details" />
                    <PagerStyle CssClass="DDFooter"/>        
                        <asp:GridViewPager runat="server" />
                        There are currently no items in this table.
                <asp:DomainDataSource ID="GridDataSource" runat="server" EnableDelete="true" />
                <asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">
                    <asp:DynamicFilterExpression ControlID="FilterRepeater" />
                <br />

    Here is the code behind:

    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.DynamicData;
    using System.Web.Routing;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.Expressions;
    using Microsoft.Web.DynamicData;
    namespace sims
    	public partial class List : System.Web.UI.Page
    		protected MetaTable table;
    		protected void Page_Init(object sender, EventArgs e)
    			table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
    			GridView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context));
    			GridDataSource.DomainServiceTypeName = table.DataContextType.AssemblyQualifiedName;
    			GridDataSource.QueryName = table.GetSelectMethod();
    			GridView1.ColumnsGenerator = new DefaultAutoFieldGenerator(table);
    			GridView1.DataKeyNames = table.PrimaryKeyColumns.Select(c => c.Name).ToArray();
    		protected void Page_Load(object sender, EventArgs e)
    			Title = table.DisplayName;
    			// Disable various options if the table is readonly
    			if (table.IsReadOnly)
    				GridView1.Columns[0].Visible = false;
    				InsertHyperLink.Visible = false;
    				GridView1.EnablePersistedSelection = false;
    			if (!table.CanInsert(Context.User))
    				InsertHyperLink.Visible = false;
    		protected void Label_PreRender(object sender, EventArgs e)
    			Label label = (Label)sender;
    			DynamicFilter dynamicFilter = (DynamicFilter)label.FindControl("DynamicFilter");
    			QueryableFilterUserControl fuc = dynamicFilter.FilterTemplate as QueryableFilterUserControl;
    			if (fuc != null && fuc.FilterControl != null)
    				label.AssociatedControlID = fuc.FilterControl.GetUniqueIDRelativeTo(label);
    		protected override void OnPreRenderComplete(EventArgs e)
    			RouteValueDictionary routeValues = new RouteValueDictionary(GridView1.GetDefaultValues());
    			InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert, routeValues);
    		protected void DynamicFilter_FilterChanged(object sender, EventArgs e)
    			GridView1.PageIndex = 0;
    		protected void SearchButton_Click(object sender, EventArgs e)

    Monday, August 5, 2013 8:16 AM