我在页面中收到以下错误:
'当前上下文'
中不存在名称'DataList1'
这是我的代码:
listviewvideo.aspx.cs
private void BindGrid()
{
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Id, Name from uploadvideo";
cmd.Connection = con;
con.Open();
DataList1.DataSource = cmd.ExecuteReader();
DataList1.DataBind();
con.Close();
}
}
}
listviewvideo.aspx
<table>
<tr>
<td>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo1" runat="server" Height="500" Width="1050"></ASPNetFlashVideo:FlashVideo>
<asp:FileUpload ID="FileUpload1" runat="server" CssClass="myButton" />
<asp:Button ID="btnupload" runat="server" Text="Upload" OnClick="btnupload_Click" CssClass="myButton" />
<hr />
<asp:DataList ID="DataList1" Visible="true" runat="server" AutoGenerateColumns="false" RepeatColumns="2" CellSpacing="5">
<ItemTemplate>
<u>
<%# Eval("Name") %>
</u>
<a class="player" style="height:300px; width:300px; display:block" href='<%# Eval("Id","FileCS.ashx?Id={0}") %>'></a>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
我在页面中收到以下错误:
'当前上下文'
中不存在名称'DataList1'
答案 0 :(得分:0)
您可能会收到此错误消息。有3个解决方案
IIS Express
。并检查它是否有效。listviewvideo.aspx.designer.cs
项目的Datalist
页面中写下以下代码。@Page
指令上的文件名和继承属性后面的代码,确保它们都匹配。此外,您可以在这里查看更清晰的图片
ID Does not exist in the current context
protected global::System.Web.UI.WebControls.DataList Datalist1;
&#13;
希望这有帮助。