Click here to Skip to main content
15,886,832 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this error "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'StudentName'.", how can I fix it ??

XML
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderSubMenu" Runat="Server">

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderMainContent" Runat="Server">

<table>
<tr>
    <td style="width:150px;">Courses</td>
    <td style="width:20px">:</td>
    <td>
        <asp:DropDownList ID="DropDownListCourses" runat="server"></asp:DropDownList>
    </td>
</tr>

<tr>
    <td style="width:150px;"></td>
    <td style="width:20px"></td>
    <td>
        <asp:Button ID="ButtonView" runat="server" Text="Veiw"
            onclick="ButtonView_Click"/>
    </td>
</tr>
</table>

<div style="padding-top:30px"></div>
<table>
<asp:Repeater ID="RepeaterDataVeiw" runat="server">

    <HeaderTemplate>
    <table>
        <tr>
        <td>Student Name</td>
        <td>Course</td>
        <td>Subject</td>
        <td>Veiw</td>

        </tr>
        </HeaderTemplate>

        <ItemTemplate>
        <tr>
        <td><%#Eval("StudentName")%></td>
        <td><%#Eval("CourseName")%></td>
        <td><%#Eval("SubjectName")%></td>
        <td><a href="ListForum.aspx">Forum</a></td>
        </tr>
        </ItemTemplate>

        <AlternatingItemTemplate>
        <tr>
         <td><%#Eval("StudentName")%></td>
        <td><%#Eval("CourseName")%></td>
        <td><%#Eval("SubjectName")%></td>
        <td><a href="ListForum.aspx">Forum</a></td>
        </tr>
        </AlternatingItemTemplate>

        <FooterTemplate>
        </table>
        </FooterTemplate>

    </asp:Repeater>
</table>

</asp:Content>


C#
public partial class Student_ListCourses : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                System.Data.DataTable  dt;
                BusinessLayer.CoursesController oCourse = new BusinessLayer.CoursesController();
                dt = oCourse.Select();
                DropDownListCourses.DataSource = dt;
                DropDownListCourses.DataValueField = "CourseID";
                DropDownListCourses.DataTextField = "CourseName";
                DropDownListCourses.DataBind();
            }
        }

        catch (Exception ex)
        { }
    }
    protected void ButtonView_Click(object sender, EventArgs e)
    {
        try
        {
            System.Data.DataTable dt;
            BusinessLayer.SubjectsController oCourse = new BusinessLayer.SubjectsController();
            oCourse.CourseID = int.Parse(DropDownListCourses.SelectedValue);
            dt = oCourse.Select();
            RepeaterDataVeiw.DataSource = dt;
            RepeaterDataVeiw.DataBind();
        }

        catch (Exception ex)
        { }
    }
}
Posted

1 solution

Really?? What the error is telling you is that your database query didn't return anything with a column called "StudentName". What you do think you should do about that? How would you diagnose that little problem?
 
Share this answer
 
Comments
Member 10193785 27-Aug-13 13:07pm    
But I have a column in the database with the same name, and I have used it in another class and it worked but with this one this one it won't
Dave Kreskowiak 27-Aug-13 13:14pm    
I don't care if it's in your database. IS IT IN THE RETURNED RESULT SET FROM THE DATABASE QUERY??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900