Showing posts with label <%# Eval("description").ToString().Replace("&". Show all posts
Showing posts with label <%# Eval("description").ToString().Replace("&". Show all posts

Wednesday, July 9, 2014

Displaying Column Data in Gridview With new line Separated By Symbol like ., @,&,#


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="grid.aspx.cs" Inherits="grid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="grd" AutoGenerateColumns="false" runat="server" 
            DataKeyNames="description"
            onrowdatabound="Unnamed1_RowDataBound">
            <Columns>
                <asp:TemplateField HeaderText="id">
                    <ItemTemplate>
                        <asp:Label ID="lbl" runat="server" Text='<%#bind("id") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="fname">
                    <ItemTemplate>
                        <asp:Label ID="lbl" runat="server" Text='<%#bind("fname") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="lname">
                    <ItemTemplate>
                        <asp:Label ID="lbl" runat="server" Text='<%#bind("lname") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Description">
                    <ItemTemplate>
                        <%# Eval("description").ToString().Replace("&","</br>")%>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
 -----------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class grid : System.Web.UI.Page
{
    string xxx = ConfigurationManager.ConnectionStrings["aaa"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection con = new SqlConnection(xxx);
            SqlCommand cmd = new SqlCommand("select * from Des");
            cmd.Connection = con;
            SqlDataAdapter dap = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            dap.Fill(ds);
            grd.DataSource = ds;
            grd.DataBind();
            //return ds;
           
        }
    }

 
}