可以帮助我在下面的代码中出错的地方 [英] can some one help me where I went wrong in the following code
本文介绍了可以帮助我在下面的代码中出错的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< asp:GridView ID = grdnewUser runat = server AutoGenerateColumns = false GridLines = 无 >
< 列 > ;
< asp:TemplateField >
< ItemTemplate >
< ul < span class =code-attribute> class = last_post >
< li >
< asp:Labe l ID = lblDateposted 文字 =' <% #Eval( DatePosted)%> ' 字体下划线 = false
< span class =code-attribute> < span class =code-attribute> runat = server > < / asp:标签 >
< / li >
< li > < strong > 在:< / strong >
< asp:标签 ID = Label1 文字 =' <% #Eval( QuestionTitle)%> ' 字体下划线 = false
< span class =code-attribute> runat = 服务器 > < / asp :标签 >
< / li >
< li > < strong > 按:< / strong >
< asp:LinkButton ID = lnkUsername runat = server 文字 =' <% #Eval( UserName)%> ' 字体下划线 = < span class =code-keyword> false > < / asp:LinkButton >
< / li >
< / ul >
< / ItemTemplate >
< / asp:TemplateField >
< /列 >
< / 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 结果{DatePosted = lastpost.DatePosted,QuestionTitle = lastpost.QuestionTitle,UserName = lastpost.UserName});
}
var query = 来自结果学生 a
选择学生;
grdnewUser.DataSource = query.ToList();
grdnewUser.DataBind();
}
错误
DataBinding:''ForumsApp.Main1 + Results''不包含属性名为''DatePosted''。
解决方案
请更改表格和网格中的DatePosted字段自动解决此错误。
<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''.
解决方案
Please Change DatePosted Field In Table and Grid Automatically Solve this Error.
这篇关于可以帮助我在下面的代码中出错的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文