Container.DataItem in ASCX problem

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Container.DataItem in ASCX problem

    I am trying to use a templated column in a datagrid and having no
    luck, here is the code of both the calling page and the ascx page.

    ..vb

    Dim MyConnection As SqlClient.SqlConnection = New
    SqlClient.SqlConnection("Database=workflow;uid=sa; pwd=newlife")
    Dim custCMD As SqlClient.SqlCommand = New
    SqlClient.SqlCommand("Select * from forma", MyConnection)
    MyConnection.Open()
    Dim myReader As SqlClient.SqlDataReader =
    custCMD.ExecuteReader()
    Dim temp As ITemplate =
    Page.LoadTemplate("webusercontrol4.ascx")
    Dim TemplateColunn As TemplateColumn
    Dim tc As New TemplateColumn
    tc.HeaderText = "Last Name"
    tc.ItemTemplate = temp
    DataGrid1.Columns.Add(tc)
    DataGrid1.DataSource = myReader
    DataGrid1.DataMember = "forma"
    DataGrid1.DataBind()

    ..ascx

    <%@ Control Language="vb" %>
    <asp:Label id=Label1 runat="server" Text='<%#
    DataBinder.Eval(Container.DataItem, "lastname")%>'>
    </asp:Label>

    I get this error message

    BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.

    I know it's probably something simple any ideas?

    Russ
    OrlandoRocks Guest

  2. Similar Questions and Discussions

    1. Container.DataItem("field") is null?
      I need to check for null values in a datagrid, unless of course there is a better way to do it. I got a field called phone, that I breakdown into a...
    2. How do you pass a DataBinder.Eval Container.DataItem to a functoin?
      I'm trying to pass a value from a data repeater to a function in my code behind page. The value is a decimal that i want to show either in red or...
    3. ascx... this time the real problem !
      You can't use a user control from another domain. If you have a control that needs to be used across domains you'll have to create a server control...
    4. [ASCX] Add an ascx in a webcontrol...
      hey there, ok i made a class, that inherits webcontrol, and i add an htmltable to it. I was wondering how to declare an ascx file as an object in...
    5. DropDownList in an .ascx file problem.
      I have a dropdownlist in an .ascx file. When using the dropdown it is workin 3 or 4 times and suddenly it gives an error like "Control...
  3. #2

    Default Container.DataItem in ASCX problem

    Quote Originally Posted by OrlandoRocks View Post
    I am trying to use a templated column in a datagrid and having no
    luck, here is the code of both the calling page and the ascx page.

    ..vb

    Dim MyConnection As SqlClient.SqlConnection = New
    SqlClient.SqlConnection("Database=workflow;uid=sa; pwd=newlife")
    Dim custCMD As SqlClient.SqlCommand = New
    SqlClient.SqlCommand("Select * from forma", MyConnection)
    MyConnection.Open()
    Dim myReader As SqlClient.SqlDataReader =
    custCMD.ExecuteReader()
    Dim temp As ITemplate =
    Page.LoadTemplate("webusercontrol4.ascx")
    Dim TemplateColunn As TemplateColumn
    Dim tc As New TemplateColumn
    tc.HeaderText = "Last Name"
    tc.ItemTemplate = temp
    DataGrid1.Columns.Add(tc)
    DataGrid1.DataSource = myReader
    DataGrid1.DataMember = "forma"
    DataGrid1.DataBind()

    ..ascx

    <%@ Control Language="vb" %>
    <asp:Label id=Label1 runat="server" Text='<%#
    DataBinder.Eval(Container.DataItem, "lastname")%>'>
    </asp:Label>

    I get this error message

    BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.

    I know it's probably something simple any ideas?

    Russ
    Move the DataItem into the quotes, like so:

    DataBinder.Eval(Container, "DataItem.lastname")
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139