Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with MulitlineTextBox 1

Status
Not open for further replies.

SarahVandenbroucke

Programmer
Mar 4, 2003
14
BE
Hi,

I have a webform with a multiline TextBox. So users can enter text here with multiple 'newlines'. The value (lets call it 'Reaction') of the TextBox is saved into the database.

Now I want a datagrid that gives an overview of all the 'Reactions' with the newlines.

What I'm getting is:
"This is an example of what I want:- all the enters must be respected- not a full block of text",

but this is what I really want:
"This is an example of what I want:
- all the enters must be respected
- not a full block of text"

Is there any way to achieve this?

Many thanks!

Sarah
 
Hi
If you just bind a off the toolbox datagrid to the datasource, you will get what you are seeing.

Probably the best way is to make an item template for that column, and use a multi-line asp.net textbox in the item template.



Mark [openup]
 
Thanks Mark for your reply!

The problem is, I then want to export the data in the datagrid to a Word document, like this:

Response.ClearHeaders()
Response.AppendHeader("Content-Disposition", "attachment; filename=""UpdateItems.doc""")
Response.ContentType = "application/msword"
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1252)
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Me.dgUpdateNieuws.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()


But if I use a multi-line textbox in the itemtemplate of that column in the datagrid, I get following error message:

Control 'dgUpdateNieuws__ctl2_tbUpdateNieuws' of type 'TextBox' must be placed inside a form tag with runat=server.

and this is the code for my datagrid:


<asp:datagrid id=&quot;dgUpdateNieuws&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; Width=&quot;100%&quot; ShowHeader=&quot;False&quot;>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<FONT face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; color=&quot;#000000&quot; size=&quot;2&quot;><B>UpdateID:
</B>
<asp:Label id=lb1 runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.updateID&quot;) %>'>
</asp:Label><BR>
<B>Datum: </B>
<asp:Label id=lb2 runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.datum&quot;) %>'>
</asp:Label><BR>
<B>Categorie: </B>
<asp:Label id=lb3 runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.categorie&quot;) %>'>
</asp:Label><BR>
<B>Vereiste versie EXE: </B>
<asp:Label id=lb4 runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.versie_EXE&quot;) %>'>
</asp:Label><BR>
<B>Onderwerp: </B>
<asp:Label id=lb5 runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.titel&quot;) %>'>
</asp:Label><BR>
<asp:TextBox ID=&quot;tbUpdateNieuws&quot; Runat=server TextMode=MultiLine Rows='<%# DataBinder.Eval(Container, &quot;DataItem.rows&quot;) %>' Text='<%# DataBinder.Eval(Container, &quot;DataItem.updatenieuws&quot;) %>' Width=100%>
</asp:TextBox>
</FONT>
<BR>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>


Any ideas??

Thanks a lot!

Sarah
 
There does not seem to be anything wrong with the code for the datagrid. Sometimes this error comes up because the VS.net 2002 IDE messes up the HTML and puts some of the controls outside the main form element in the HTML. On the Tools, Options menu in the IDE, and then in the Text Editor, HTML/XML, Format, I've turned off all the check boxes and set the two drop downs to &quot;As entered&quot;, and I seem to remember this solving the problem for me. I've not yet had a lot of experience with the VS.net 2003 quirks like this...

I've never done what you are attempting, but it looks pretty useful, so thanks!

Mark

Mark [openup]
 
Actually, I've played with this and it is nothing to do with the VS IDE. I think it may be because your code is trying to put a text box tag in the page header section of the HTML.

An alternative way of displaying line breaks correctly, without using a multiline text box, is as follows

Code:
        'Put user code to initialize the page here
        Conn.Open()
        Dim dr As OleDb.OleDbDataReader
        dr = cmd.ExecuteReader
        dgGrid.DataSource = dr
        dgGrid.DataBind()
        dr.Close()
        Conn.Close()

Code:
        Dim dgRow As DataGridItem, tbCell As TableCell, lblLabel As Label
        For Each dgRow In dgGrid.Items
            tbCell = dgRow.Cells(1)
            lblLabel = CType(tbCell.Controls(1), Label)
            lblLabel.Text = Replace(lblLabel.Text, ControlChars.CrLf, &quot;<br>&quot;)
        Next

[/code]

The code works for this datagrid

Code:
    <form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;><asp:DataGrid id=dgGrid runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot;>
<Columns>
<asp:TemplateColumn HeaderText=&quot;ID&quot;>
<ItemTemplate>
<asp:Label runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.ID&quot;) %>'></asp:Label>
</ItemTemplate>

</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=&quot;Symptom&quot;>
<ItemTemplate>
<asp:label runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.Symptom&quot;) %>'></asp:label>
</ItemTemplate>

</asp:TemplateColumn>
</Columns>
</asp:DataGrid><asp:Button id=btnDownload runat=&quot;server&quot; Text=&quot;Word&quot;></asp:Button>

Hope this helps you.


Mark [openup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top