How To Split String and Display in GridView-ASP.NET

Let’s suppose you have CSV data and you want to show it in ASP.NET web application, for example, in GridView Control. This article will explain how to achieve this goal using C#.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="" >
<head runat="server">
  <title>Untitled Page</title>
  <form id="form1" runat="server">
 Original String<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br />
 Separator<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
 <asp:Button ID="btnConvert" runat="server" Text="Split" OnClick="btnConvert_Click" />
 <asp:GridView ID="GridView1" runat="server"></asp:GridView>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class SplitFunctionUsingRegx : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void btnConvert_Click(object sender, EventArgs e)
        string str = TextBox1.Text;
        string strSplit = TextBox2.Text;
        ArrayList arSplit = new ArrayList();
        Regex r = new Regex(strSplit);
        string[] s = r.Split(str);
        foreach (object o in s)



        GridView1.DataSource = arSplit;

Next Post Previous Post
No Comment
Add Comment
comment url