Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I get the following error in a page:
'The name 'DataList1' does not exist in the current context'
Hereunder is my code:

XML
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
      <style type="text/css">
    </style>
</head>
<body >
    <form id="form1" runat="server">
    <div >
   <asp:DataList ID="DataList11" runat="server"  RepeatColumns="2"   RepeatDirection="Horizontal"  >
                  <ItemTemplate>
                             <table id="Table1" cellpadding="1" cellspacing="1" visible ="true">
                                    <tr>
                                            <td width="140px">
                                            <p align="left">
                                             <b>Product ID: </b>
                                                 <asp:Label ID="lblEmpCode" runat ="server" CssClass="LabelStyle"
                                                 Text= '<%#DataBinder.Eval(Container.DataItem, "product_id")%>'>
                                                 </asp:Label>
                                            </p>
                                         </td>
                                     </tr>
                              </table>
                       </ItemTemplate>
</asp:DataList>
    </div>
    </form>
</body>
</html>


C#
public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["prasiddhiConnectionString"].ConnectionString);
    static int v_rate;
    protected void Page_Load(object sender, EventArgs e)
    {
        List<string> adds9 = new List<string>();
        SqlDataAdapter da9 = new SqlDataAdapter("select * from product", con);
        SqlCommandBuilder cb9 = new SqlCommandBuilder(da9);
        DataSet ds9 = new DataSet("product");
        da9.Fill(ds9, "product");
        //int v_rowcount1 = 0;
        for (int i = 0; i < ds9.Tables[0].Rows.Count; i++)
        {
        }
        DataList1.DataSource = ds9;
        DataList1.DataBind();
        DataList1.Visible = true;

    }
}</string></string>
Posted
Updated 13-Nov-13 23:12pm
v2

You have used incorrect ID of Datalist. the actual datalist ID is DataList11 but you have used DataList1

please replace your code with

DataList11.DataSource = ds9;
DataList11.DataBind();
DataList11.Visible = true;
 
Share this answer
 
Comments
♥…ЯҠ…♥ 14-Nov-13 5:12am    
Good catch..!!!
Tom Marvolo Riddle 14-Nov-13 5:12am    
Detected 5+
S.Rajendran from Coimbatore 14-Nov-13 5:13am    
Well. But still I get the same error
♥…ЯҠ…♥ 14-Nov-13 6:32am    
Clean the solution, rebuild it and check it out since error seems to be self descriptive.....
C#
DataList11
is your id defined in aspx page and you are referring
C#
DataList1
this id in cs file
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 14-Nov-13 5:14am    
Well. I rectified but still get the same error.
vinayakJJ 14-Nov-13 5:19am    
update your code here
S.Rajendran from Coimbatore 14-Nov-13 5:21am    
DataList11.DataSource = ds9;
DataList11.DataBind();
DataList11.Visible = true;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900