[英]Repeater DataBind error
Half a day spent on this one...花了半天时间在这个...
On a page, I have two repeaters like so:在一个页面上,我有两个这样的转发器:
<% if (String.IsNullOrEmpty(Request.QueryString["id"])) { %>
<asp:Repeater ID="auth_items" runat="server">
<ItemTemplate>
<a href="/admin/auth.aspx?action=view&id=<%# Eval("id") %>"><%# Security.script(Eval("name").ToString()) %></a><br />
</ItemTemplate>
</asp:Repeater>
<% } else { %>
<asp:Repeater ID="auth_item" runat="server">
<ItemTemplate>
<%# Security.script(Eval("name").ToString()) %>
</ItemTemplate>
</asp:Repeater>
<% } %>
and in code behind:在后面的代码中:
if (String.IsNullOrEmpty(Request.QueryString["id"]))
sql = "SELECT * FROM table1 ORDER BY attr1 DESC";
else
{
id = Security.sql(Request.QueryString["id"]);
sql = "SELECT * FROM table2 WHERE attr2=" + id;
}
s.OpenConn(sql);
if (String.IsNullOrEmpty(Request.QueryString["id"]))
{
auth_items.DataSource = s.GetRead();
auth_items.DataBind();
}
else
{
auth_item.DataSource = s.GetRead();
auth_item.DataBind();
}
The problem is that I get 'object reference not set to an instance of an object' on auth_item.DataBind().问题是我在 auth_item.DataBind() 上得到“对象引用未设置为对象的实例”。 First repeater works fine and displays the data, but the second one won't work and instead, throws me an error.
第一个中继器工作正常并显示数据,但第二个中继器不起作用,而是给我一个错误。 I debugged it and DataSource for the second repeater is not null, and sql returns a value.
我对其进行了调试,第二个中继器的 DataSource 不是 null,sql 返回一个值。
What seems to be the problem?似乎是什么问题?
Thank you!谢谢!
table2 doesn't have a name column? table2 没有名称列?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.