System.Web.UI.Page?

  • Thread starter Thread starter Arpan
  • Start date Start date
A

Arpan

Consider the following code:

<form runat="server">
<asp:DataList ID="dlUsers" OnCancelCommand="CancelList"
OnDeleteCommand="DeleteList" OnEditCommand="EditList"
OnItemCommand="ItemList" OnUpdateCommand="UpdateList"
RepeatDirection="horizontal" RepeatLayout="table" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkButton" CommandName="Edit" runat="server"><%#
Container.DataItem("FirstName") %></asp:LinkButton>
&nbsp;&nbsp;&nbsp;&nbsp;
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkCancel" CommandName="Cancel" Text="Cancel"
runat="server"/>
<asp:LinkButton ID="lnkUpdate" CommandName="Update" Text="Update"
runat="server"/>
<asp:LinkButton ID="lnkDelete" CommandName="Delete" Text="Delete"
runat="server"/>
</EditItemTemplate>
</asp:DataList>
</form>

The event handlers for the different events are not shown here. As such
the above code works fine but if I add a TextBox control immediately
after the opening <form> tag & keep the rest of the code as it is

<form runat="server">
<asp:TextBox ID="txtFName" Text=<%# Container.DataItem("FirstName") %>
runat="server"/>
<%-- rest of the code comes here as shown above --%>

then the VWD 2005 IDE generates the following error:

'DataItem' is not a member of 'System.Web.UI.Page'

pointing to the line

<asp:LinkButton ID="lnkButton" CommandName="Edit" runat="server"><%#
Container.DataItem("FirstName") %></asp:LinkButton>

but when I run the page in IE6, the same error gets generated but this
time pointing to the line

<asp:TextBox ID="txtValue" Text=<%# Container.DataItem("FirstName") %>
runat="server"/>

First of all, what's causing the above error? Secondly, why is the VWD
IDE & the .NET compiler pointing to 2 different code lines though both
of them are generating the same error?

Thanks,

Arpan
 
The error is because you are placing the textbox control outside a
non-databound control.. i.e. a datagrid or datalist or repeater.. If
you want to use a value from the datalist data source.. you need to
keep it inside the datalist templates..

if you want to assign a value to textbox.. then it should be inside an
ItemTemplate or EditItemTemplate
 
First of all, many many thanks for your explanations.
The error is because you are placing the textbox control outside a
non-databound control.. i.e. a datagrid or datalist or repeater.. If
you want to use a value from the datalist data source.. you need to
keep it inside the datalist templates..

You mean to say that to assign a value to any non-boundable web server
control (like TextBox, LinkButton, Button, Hyperlink etc..) from a data
binding control (i.e. DataList or DataGrid or Repeater) data source,
the non-boundable web server control SHOULD be placed within any of the
templates of the data binding control (i.e. DataList or DataGrid or
Repeater)......am I right? Please correct me if I have got it wrong.

Thanks once again,

Regards,

Arpan
 
Yes, You are right!
First of all, many many thanks for your explanations.


You mean to say that to assign a value to any non-boundable web server
control (like TextBox, LinkButton, Button, Hyperlink etc..) from a data
binding control (i.e. DataList or DataGrid or Repeater) data source,
the non-boundable web server control SHOULD be placed within any of the
templates of the data binding control (i.e. DataList or DataGrid or
Repeater)......am I right? Please correct me if I have got it wrong.

Thanks once again,

Regards,

Arpan
 
Back
Top