So, I've got a gridview which has an edit mode (in the normal mode, the containers are labels, and in edit mode textboxes). This is done by some TemplateFields, ItemTemplate, EditTemplate, etc. For example, (in my asp GridView):
The problem is this: When a user is making a new line in edit mode (pushing enter), this is not to be seen in the label. In the label, all text are being wrapped together. If I turn the gridview into edit mode again, the textboxes still got the correct number
of lines.
So, what I want here is therefore some sort of a "multiline" Label, so that the text in the Label appears in the same manner as in the TextBox.
(One soloution could be that the ItemTemplate also can be a TextBox, but that causes some other problems, like the height of that textbox should auto-grow, etc)
You need to replace your line breaks (\r\n) with html breaks (<br/>). A line break works in a text box, but not in a label. If you want a break in a label you need an html break. I don't know how you do this with Eval, but try something like this;
Zoizaite
Member
6 Points
13 Posts
Going from a multiline textbox to a label!
Dec 03, 2012 06:30 AM|LINK
Hello good sirs!
So, I've got a gridview which has an edit mode (in the normal mode, the containers are labels, and in edit mode textboxes). This is done by some TemplateFields, ItemTemplate, EditTemplate, etc. For example, (in my asp GridView):
<asp:TemplateField HeaderText="Kommentar">
<ItemTemplate >
<asp:Label ID="lcgCommentLabel" runat="server" Width="600px" Text='<%# Eval("Kommentar") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="lcgCommentTextBox" Width="594px" TextMode="MultiLine" runat="server" Text='<%# Eval("Kommentar")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
And the information is saved to an SQL Database.
The problem is this: When a user is making a new line in edit mode (pushing enter), this is not to be seen in the label. In the label, all text are being wrapped together. If I turn the gridview into edit mode again, the textboxes still got the correct number of lines.
So, what I want here is therefore some sort of a "multiline" Label, so that the text in the Label appears in the same manner as in the TextBox.
(One soloution could be that the ItemTemplate also can be a TextBox, but that causes some other problems, like the height of that textbox should auto-grow, etc)
Hope I am somewhat clear.
Anyone got some ideas? Thanks in beforehand!
AidyF
Star
9204 Points
1570 Posts
Re: Going from a multiline textbox to a label!
Dec 03, 2012 09:01 AM|LINK
You need to replace your line breaks (\r\n) with html breaks (<br/>). A line break works in a text box, but not in a label. If you want a break in a label you need an html break. I don't know how you do this with Eval, but try something like this;
<asp:Label ID="lcgCommentLabel" runat="server" Width="600px" Text='<%# Eval("Kommentar").ToString().Replace("\r\n", "<br/>") %>'></asp:Label>Jack Hunt
Participant
1270 Points
713 Posts
Re: Going from a multiline textbox to a label!
Dec 03, 2012 09:13 AM|LINK
set fix width to lable and in edit mode set textbox property.....textmode="multiline"
mit's Website
Mitesh N Vaishnav
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Going from a multiline textbox to a label!
Dec 04, 2012 01:37 AM|LINK
Do you mean your Label disappears in the edit mode of GridView?