Databound textbox issue - need urgent help

J

jagbal

Hi,

I am using a Datagrid for displaying records from the SQL Server
database.

I am having the foll. code in the .aspx page
------------------------------------------------------------------------------------
<asp:TemplateColumn SortExpression="AMOUNT"
HeaderText="Amount">
<ItemStyle HorizontalAlign="Right"
VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<asp:Label id=lblAmount Text='<%# String.Format("{0:N}",
Convert.ToInt32(Container.DataItem("Amount"))) %>'
Runat="server">
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtAmount" Runat="server">
<%# Container.DataItem("Amount") %>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
------------------------------------------------------------------------------------
I am trying to display the "Amount" in formatted way and i am able to
do it.
When i am trying to edit the record in the datagrid by clicking the
edit link, it is giving me the foll. error

Server Error in '/ConsHistory' Application.
--------------------------------------------------------------------------------

'TextBox' cannot have children of type 'DataBoundLiteralControl'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 'TextBox' cannot have
children of type 'DataBoundLiteralControl'.

Source Error:


Line 160: </ItemTemplate>
Line 161: <EditItemTemplate>
Line 162: <asp:TextBox id="txtAmount" Runat="server">
Line 163: <%# Container.DataItem("Amount") %>
Line 164: </asp:TextBox>
-----------------------------------------------------------------------
I need some one to help me in editing the record in the formatted
way.

Thanks in advance

Regards,
Bala
 
C

Craig Deelsnyder

jagbal said:
'TextBox' cannot have children of type 'DataBoundLiteralControl'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 'TextBox' cannot have
children of type 'DataBoundLiteralControl'.

Source Error:


Line 160: </ItemTemplate>
Line 161: <EditItemTemplate>
Line 162: <asp:TextBox id="txtAmount" Runat="server">
Line 163: <%# Container.DataItem("Amount") %>
Line 164: </asp:TextBox>

The textbox can't have any text (which is translated to a literal)
inside its tags. What you want is to bind to its Value:

<asp:TextBox id="txtAmount" Runat="server" Value='<%#
Container.DataItem("Amount") %>' />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top