“DataList1'这个名字并不在目前的情况下存在 [英] The name 'DataList1' does not exist in the current context
本文介绍了“DataList1'这个名字并不在目前的情况下存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下错误页:
DataList1'名称''不在当前上下文中存在'
块引用>下面是我的code:
listviewvideo.aspx.cs
私人无效BindGrid()
{
字符串strConnString = ConfigurationManager.ConnectionStrings [构造]的ConnectionString。
使用(SqlConnection的CON =新的SqlConnection(strConnString))
{
使用(CMD的SqlCommand =新的SqlCommand())
{
cmd.CommandText =选择编号,从uploadvideo名;
cmd.Connection = CON;
con.Open();
DataList1.DataSource = cmd.ExecuteReader();
DataList1.DataBind();
con.Close();
}
}
}listviewvideo.aspx
<表>
&所述; TR>
&所述; TD>
< ASPNetFlashVideo:FlashVideo ID =FlashVideo1=服务器HEIGHT =500WIDTH =1050>< / ASPNetFlashVideo:FlashVideo>
< ASP:文件上传ID =FileUpload1=服务器的CssClass =myButton的/>
< ASP:按钮的ID =btnupload=服务器文本=上传的OnClick =btnupload_Click的CssClass =myButton的/>
<小时/>
< ASP:DataList控件ID =DataList1可见=真=服务器的AutoGenerateColumns =false的RepeatColumns =2CELLSPACING =5>
<&ItemTemplate中GT;
< U>
<%#的eval(姓名)%>
< / U>
<一类=播放器的风格=高度:300像素;宽度:300像素,显示:块的href ='<%#的eval(ID,FileCS.ashx ID = {0}?)%&GT ;'>&下; / A>
< / ItemTemplate中>
< / ASP:DataList控件>
< / TD>
< / TR>
< /表>我收到以下错误页:
DataList1'名称''不在当前上下文中存在'
块引用>解决方案您可能会得到这个错误。有这3解决方案
- 保存项目,并关闭该解决方案,关闭
IIS防爆preSS
也。并检查它是否有效与否。
- 尝试通过在其中添加你的
listviewvideo.aspx.designer.cs
页写低于code添加在DataList的DataList控件
项目。
- 检查隐藏文件名,并在
@Page
指令继承财产的code,确保它们都匹配。您也可以看看这里的更多清晰的图片。
\r\r\r\r保护全球:: System.Web.UI.WebControls.DataList Datalist1;
\r
希望这有助于。
I get the following error in a page:
'The name 'DataList1' does not exist in the current context'
Here is my code:
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>
I get the following error in a page:
'The name 'DataList1' does not exist in the current context'
解决方案You might get this error. There 3 solutions for this
- Save your project and close the Solution, close the
IIS Express
also. And check whether it works or not.
- Try adding the the datalist by writing below code in your
listviewvideo.aspx.designer.cs
page of where you are adding theDatalist
item.
- Check your code behind file name and Inherits property on the
@Page
directive, make sure they both match.Also you can have a look here for more clear picture
ID Does not exist in the current context
protected global::System.Web.UI.WebControls.DataList Datalist1;
Hope this helps.
这篇关于“DataList1'这个名字并不在目前的情况下存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文