Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Can't figure out the error:does not exist in the current context

Can't figure out the error:does not exist in the current context

Scheduled Pinned Locked Moved ASP.NET
helpdesignsysadmin
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Albert83
    wrote on last edited by
    #1

    Hello everybody, I am getting an error: The name 'DataList1' does not exist in the current context. DataList1 is a data list the code is in two pages: Have no idea what the problem is. Any assistance is appreciated. groups.aspx, and groups.aspx.cs groups.aspx: I remobed the open tags so that the code can be seen. asp:DataList ID="DataList1" runat="server" DataSourceID="ChalkDL"> ItemTemplate> asp:TextBox ID="postComment" runat="server"> asp:Button runat="server" OnClick="postBtn_Click" ID="postBtn" Text="Post!" /> /ItemTemplate> /asp:DataList> groups.aspx.cs protected void postBtn_Click(object sender, EventArgs e) { SqlDataSource PostDS = new SqlDataSource(); System.Web.UI.WebControls.TextBox PostText = (System.Web.UI.WebControls.TextBox)DataList1.FindControl("postComment"); PostDS.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); PostDS.InsertCommandType = SqlDataSourceCommandType.Text; PostDS.InsertCommand = "INSERT INTO GroupChalkboard (Text, GroupID, UserID, CreatedDate) VALUES (@Text, @GroupID, @UserID, @CreatedDate)"; PostDS.InsertParameters.Add("Text", PostText.Text); PostDS.InsertParameters.Add("GroupID", pid.ToString()); PostDS.InsertParameters.Add("UserID", Session["UserID"].ToString()); PostDS.InsertParameters.Add("CreatedDate", DateTime.Now.ToString()); PostDS.Insert(); }

    I 1 Reply Last reply
    0
    • A Albert83

      Hello everybody, I am getting an error: The name 'DataList1' does not exist in the current context. DataList1 is a data list the code is in two pages: Have no idea what the problem is. Any assistance is appreciated. groups.aspx, and groups.aspx.cs groups.aspx: I remobed the open tags so that the code can be seen. asp:DataList ID="DataList1" runat="server" DataSourceID="ChalkDL"> ItemTemplate> asp:TextBox ID="postComment" runat="server"> asp:Button runat="server" OnClick="postBtn_Click" ID="postBtn" Text="Post!" /> /ItemTemplate> /asp:DataList> groups.aspx.cs protected void postBtn_Click(object sender, EventArgs e) { SqlDataSource PostDS = new SqlDataSource(); System.Web.UI.WebControls.TextBox PostText = (System.Web.UI.WebControls.TextBox)DataList1.FindControl("postComment"); PostDS.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); PostDS.InsertCommandType = SqlDataSourceCommandType.Text; PostDS.InsertCommand = "INSERT INTO GroupChalkboard (Text, GroupID, UserID, CreatedDate) VALUES (@Text, @GroupID, @UserID, @CreatedDate)"; PostDS.InsertParameters.Add("Text", PostText.Text); PostDS.InsertParameters.Add("GroupID", pid.ToString()); PostDS.InsertParameters.Add("UserID", Session["UserID"].ToString()); PostDS.InsertParameters.Add("CreatedDate", DateTime.Now.ToString()); PostDS.Insert(); }

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      Albert83 wrote:

      System.Web.UI.WebControls.TextBox PostText = (System.Web.UI.WebControls.TextBox)DataList1.FindControl("postComment");

      This line should be TextBox PostText=(TextBox)DataList1.Items[IndexHere].FindControl("PostComment");

      Albert83 wrote:

      I am getting an error: The name 'DataList1' does not exist in the current context.

      Can you get DataList1 control in codebehind side? If no, It should be inherit problem of the page. Check page directory of groups.aspx and class name of groups.aspx.cs.

      please don't forget to vote on the post that helped you.

      A 1 Reply Last reply
      0
      • I Imran Khan Pathan

        Albert83 wrote:

        System.Web.UI.WebControls.TextBox PostText = (System.Web.UI.WebControls.TextBox)DataList1.FindControl("postComment");

        This line should be TextBox PostText=(TextBox)DataList1.Items[IndexHere].FindControl("PostComment");

        Albert83 wrote:

        I am getting an error: The name 'DataList1' does not exist in the current context.

        Can you get DataList1 control in codebehind side? If no, It should be inherit problem of the page. Check page directory of groups.aspx and class name of groups.aspx.cs.

        please don't forget to vote on the post that helped you.

        A Offline
        A Offline
        Albert83
        wrote on last edited by
        #3

        I can't get the DataList in code behind that's the problem. The weird thing DataList1 does show up in the list and I can choose Items property and find control property. But when I run it, it says DataList1 does not exist in the current context. How to resolve it ? That's aspx: %@ Page Language="C#" AutoEventWireup="true" CodeFile="groups.aspx.cs" Inherits="groups" %> that's aspx.cs public partial class groups : System.Web.UI.Page { Also In this code: TextBox PostText=(TextBox)DataList1.Items[IndexHere].FindControl("PostComment"); what's Items[IndexHere] - what index is that. Should I count the number of items in the ItemTemplate?

        I 1 Reply Last reply
        0
        • A Albert83

          I can't get the DataList in code behind that's the problem. The weird thing DataList1 does show up in the list and I can choose Items property and find control property. But when I run it, it says DataList1 does not exist in the current context. How to resolve it ? That's aspx: %@ Page Language="C#" AutoEventWireup="true" CodeFile="groups.aspx.cs" Inherits="groups" %> that's aspx.cs public partial class groups : System.Web.UI.Page { Also In this code: TextBox PostText=(TextBox)DataList1.Items[IndexHere].FindControl("PostComment"); what's Items[IndexHere] - what index is that. Should I count the number of items in the ItemTemplate?

          I Offline
          I Offline
          Imran Khan Pathan
          wrote on last edited by
          #4

          Albert83 wrote:

          The weird thing DataList1 does show up in the list and I can choose Items property and find control property.

          Did you get runtime error or compile time error?

          Albert83 wrote:

          In this code: TextBox PostText=(TextBox)DataList1.Items[IndexHere].FindControl("PostComment"); what's Items[IndexHere] - what index is that. Should I count the number of items in the ItemTemplate?

          Yes.you have to do looping through datalist items.

          please don't forget to vote on the post that helped you.

          A 1 Reply Last reply
          0
          • I Imran Khan Pathan

            Albert83 wrote:

            The weird thing DataList1 does show up in the list and I can choose Items property and find control property.

            Did you get runtime error or compile time error?

            Albert83 wrote:

            In this code: TextBox PostText=(TextBox)DataList1.Items[IndexHere].FindControl("PostComment"); what's Items[IndexHere] - what index is that. Should I count the number of items in the ItemTemplate?

            Yes.you have to do looping through datalist items.

            please don't forget to vote on the post that helped you.

            A Offline
            A Offline
            Albert83
            wrote on last edited by
            #5

            I got the error after I clicked Run, and it says Build failed. I guess it compile erro. What's the difference between run time and compile.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups