kurczę nie wiem testowałem na Visual 2005 i 2010, poniżej masz pełny kod udoskonalony, działa u mnie, bez znacznków podczas wyświetlania w textboxie
kod asp.net (najważniejsze przy Labelu zamień na Eval i wprowadź Replace)
Kopiuj
<div>
<asp:GridView ID="GridView1" AutoGenerateColumns = "false" runat="server"
DataSourceID="SqlDataSource1" AutoGenerateEditButton = "true"
DataKeyNames = "news_number" >
<Columns>
<asp:TemplateField HeaderText="News_text" SortExpression="News_text">
<EditItemTemplate>
<asp:TextBox runat="server" TextMode="MultiLine" Text='<%# Bind("news_text") %>' ID="TextBox1" OnTextChanged = "TextBox1_TextChanged" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("news_text").ToString().Replace("\n", "<br />") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:szymonConnectionString %>"
SelectCommand="SELECT [news_number], [news_text] FROM [news_test]"
UpdateCommand="UPDATE [news_test] SET [news_text] = @news_text where [news_number] = @news_number" >
<UpdateParameters>
<asp:Parameter Type = "Int32" Name = "news_number" />
<asp:Parameter Type = "String" Name = "news_text" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
kod z CodeBehind
Kopiuj
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox thisTextBox = (TextBox)sender;
GridViewRow thisGridViewRow = (GridViewRow)thisTextBox.Parent.Parent;
int row = thisGridViewRow.RowIndex;
TextBox w = (TextBox)GridView1.Rows[row].Cells[0].FindControl("TextBox1");
w.Text = w.Text.Replace(Environment.NewLine, "\n");
}
Jeśli masz coś podobnego to musi działać. Być może wywala Ci błąd o niebezpiecznej zawartości, to w sekcji Page dodaj ValidateRequest="false".