Click here to Skip to main content
15,891,811 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:GridView ID="grdnewUser" runat="server" AutoGenerateColumns="false" GridLines="None">
                                            <Columns>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <ul class="last_post">
                                                            <li>
                                                                <asp:Label ID="lblDateposted" Text='<%#Eval("DatePosted") %>' Font-Underline="false"
                                                                    runat="server"></asp:Label>
                                                            </li>
                                                            <li><strong>In:</strong>
                                                                <asp:Label ID="Label1" Text='<%#Eval("QuestionTitle") %>' Font-Underline="false"
                                                                    runat="server"></asp:Label>
                                                            </li>
                                                            <li><strong>By:</strong>
                                                                <asp:LinkButton ID="lnkUsername" runat="server" Text='<%#Eval("UserName") %>' Font-Underline="false"></asp:LinkButton>
                                                            </li>
                                                        </ul>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                        </asp:GridView>


C#
public void bindLastPost()
        {
            ArrayList a = new ArrayList();

            foreach (GridViewRow row in grdForum.Rows)
            {
                int quesID = Convert.ToInt16(grdForum.DataKeys[row.RowIndex].Values["TechID"].ToString());
                var lastpost = db.tblQuestions.Where(u => u.TechID.Equals(quesID)).OrderByDescending(u => u.DatePosted).Take(1).FirstOrDefault();

                a.Add(new Results { DatePosted = lastpost.DatePosted, QuestionTitle = lastpost.QuestionTitle, UserName = lastpost.UserName });
            }

            var query = from Results student in a
                        select student;
            grdnewUser.DataSource = query.ToList();
            grdnewUser.DataBind();
}


error
DataBinding: 'ForumsApp.Main1+Results' does not contain a property with the name 'DatePosted'.
Posted

1 solution

Please Change DatePosted Field In Table and Grid Automatically Solve this Error.
 
Share this answer
 
Comments
demouser743 2-Feb-13 3:19am    
Change to what

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