Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 04, 2013 12:14 AM by Decker Dong - MSFT
Member
275 Points
367 Posts
Feb 02, 2013 06:12 AM|LINK
<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>
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'
Contributor
5120 Points
1459 Posts
Feb 02, 2013 12:16 PM|LINK
Dora743 Dora743
Very weird, if the Results has DatePosted propertiy. Please show you model and other codes.
Feb 02, 2013 12:17 PM|LINK
There is no more code than that to show
Feb 02, 2013 12:29 PM|LINK
Dora743 There is no more code than that to show
Just debug with step into then take a look what goes wrong there. You will see all data structure.
Feb 02, 2013 12:30 PM|LINK
My data is getting as per I written code but unable to bind to the girdivew
Feb 02, 2013 12:41 PM|LINK
Changes to the List<T>
var a = new List<Results>();
Feb 02, 2013 12:47 PM|LINK
same error error DataBinding: 'ForumsApp.Main1+Results' does not contain a property with the name 'DatePosted'
Feb 02, 2013 12:53 PM|LINK
I am not expert in ASP.net but I have seen lots sample ues associate with datatable or DataSet ds.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.datasource.aspx
All-Star
118619 Points
18779 Posts
Feb 04, 2013 12:14 AM|LINK
Dora743 error DataBinding: 'ForumsApp.Main1+Results' does not contain a property with the name 'DatePosted'
Hi,
You must include the property as a public one to bind to the data source control of your GridView.
Dora743
Member
275 Points
367 Posts
Can some one help me where I went wrong with the code
Feb 02, 2013 06:12 AM|LINK
<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>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'
Mindcracker MVP
http://dorababu-meka.blogspot.in/
thaicarrot
Contributor
5120 Points
1459 Posts
Re: Can some one help me where I went wrong with the code
Feb 02, 2013 12:16 PM|LINK
Very weird, if the Results has DatePosted propertiy. Please show you model and other codes.
Weera
Dora743
Member
275 Points
367 Posts
Re: Can some one help me where I went wrong with the code
Feb 02, 2013 12:17 PM|LINK
There is no more code than that to show
Mindcracker MVP
http://dorababu-meka.blogspot.in/
thaicarrot
Contributor
5120 Points
1459 Posts
Re: Can some one help me where I went wrong with the code
Feb 02, 2013 12:29 PM|LINK
Just debug with step into then take a look what goes wrong there. You will see all data structure.
Weera
Dora743
Member
275 Points
367 Posts
Re: Can some one help me where I went wrong with the code
Feb 02, 2013 12:30 PM|LINK
My data is getting as per I written code but unable to bind to the girdivew
Mindcracker MVP
http://dorababu-meka.blogspot.in/
thaicarrot
Contributor
5120 Points
1459 Posts
Re: Can some one help me where I went wrong with the code
Feb 02, 2013 12:41 PM|LINK
Changes to the List<T>
var a = new List<Results>();
Weera
Dora743
Member
275 Points
367 Posts
Re: Can some one help me where I went wrong with the code
Feb 02, 2013 12:47 PM|LINK
same error error DataBinding: 'ForumsApp.Main1+Results' does not contain a property with the name 'DatePosted'
Mindcracker MVP
http://dorababu-meka.blogspot.in/
thaicarrot
Contributor
5120 Points
1459 Posts
Re: Can some one help me where I went wrong with the code
Feb 02, 2013 12:53 PM|LINK
I am not expert in ASP.net but I have seen lots sample ues associate with datatable or DataSet ds.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.datasource.aspx
Weera
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Can some one help me where I went wrong with the code
Feb 04, 2013 12:14 AM|LINK
Hi,
You must include the property as a public one to bind to the data source control of your GridView.