ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display data from database in ASP.Net GridView with Line Break using C# and VB.Net<p>I will get back soon.</p>https://www.aspforums.net:443/Threads/203438/Display-data-from-database-in-ASPNet-GridView-with-Line-Break-using-C-and-VBNet/https://www.aspforums.net:443/Threads/203438/Display-data-from-database-in-ASPNet-GridView-with-Line-Break-using-C-and-VBNet/Thu, 04 Jul 2019 00:25:09 GMTDisplay data from database in ASP.Net GridView with Line Break using C# and VB.Net<p>Hi <a class="username" rel="jqdesigner"> jqdesigner</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">Date : &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtDate&#34; /&gt; &lt;br /&gt; Time : &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtTime&#34; /&gt; &lt;br /&gt; Comments : &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtComments&#34; TextMode=&#34;MultiLine&#34; /&gt; &lt;br /&gt; &lt;asp:Button Text=&#34;Insert&#34; runat=&#34;server&#34; OnClick=&#34;Insert&#34; /&gt; &lt;br /&gt; &lt;asp:GridView runat=&#34;server&#34; ID=&#34;GridView1&#34; AutoGenerateColumns=&#34;false&#34; OnRowDataBound=&#34;GridView1_RowDataBound&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;ieComment&#34; HeaderText=&#34;Content&#34; HtmlEncode=&#34;false&#34; /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:Label Text=&#39;&lt;%#Eval(&#34;ieComment&#34;) %&gt;&#39; runat=&#34;server&#34; ID=&#34;lblContent&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using System.Data.SqlClient; using System.Configuration;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { BindGrid(); } private void BindGrid() { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;SELECT * FROM tblInterView&#34;, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } protected void Insert(object sender, EventArgs e) { string iDate = txtDate.Text; string isComment = &#34;Interview Date: &#34; + iDate + &#34; &lt;br /&gt; Interview Time: &#34; + txtTime.Text + &#34;&lt;br /&gt; &#34; + txtComments.Text; string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;INSERT INTO tblInterView VALUES(@ieComment)&#34;, con); cmd.Parameters.AddWithValue(&#34;@ieComment&#34;, isComment); con.Open(); cmd.ExecuteNonQuery(); con.Close(); BindGrid(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { (e.Row.FindControl(&#34;lblContent&#34;) as Label).Text = Server.HtmlDecode(e.Row.Cells[0].Text); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load BindGrid() End Sub Private Sub BindGrid() Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim con As SqlConnection = New SqlConnection(constr) Dim cmd As SqlCommand = New SqlCommand(&#34;SELECT * FROM tblInterView&#34;, con) Dim da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim dt As DataTable = New DataTable() da.Fill(dt) GridView1.DataSource = dt GridView1.DataBind() End Sub Protected Sub Insert(ByVal sender As Object, ByVal e As EventArgs) Dim iDate As String = txtDate.Text Dim isComment As String = &#34;Interview Date: &#34; &amp; iDate &amp; &#34; &lt;br /&gt; Interview Time: &#34; &amp; txtTime.Text &amp; &#34;&lt;br /&gt; &#34; + txtComments.Text Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim con As SqlConnection = New SqlConnection(constr) Dim cmd As SqlCommand = New SqlCommand(&#34;INSERT INTO tblInterView VALUES(@ieComment)&#34;, con) cmd.Parameters.AddWithValue(&#34;@ieComment&#34;, isComment) con.Open() cmd.ExecuteNonQuery() con.Close() BindGrid() End Sub Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then TryCast(e.Row.FindControl(&#34;lblContent&#34;), Label).Text = Server.HtmlDecode(e.Row.Cells(0).Text) End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/TpLcXhh.gif" alt="" width="332" height="352" /></p>https://www.aspforums.net:443/Threads/203438/Display-data-from-database-in-ASPNet-GridView-with-Line-Break-using-C-and-VBNet/https://www.aspforums.net:443/Threads/203438/Display-data-from-database-in-ASPNet-GridView-with-Line-Break-using-C-and-VBNet/Thu, 04 Jul 2019 03:06:54 GMT