Wednesday, November 28, 2012

String to DataTable in using C#.Net

Title:How to bind data table using string array in using c#

We have already learnt data binding to data source controls.Now i would like to show how would we use the array list to bind the data to grid view etc.

Some  examples for JQuery Auto complete text boxhow to bind or Export CSV data to data table in below example describes the logic of iteration of array list to  data table.In the below i have used a string array to hold the string data and a grid view to display the resultant data of Data table.
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:GridView ID="GvOrdr" runat="server"></asp:GridView>

DataTable dtOrdrName = new DataTable();
dtOrdrName.Columns.Add(new DataColumn("Name", typeof(string)));
string[] strSplitOp = new string[] { "bhaskar", "Siva", "Ram" };
for (int i = 0; i <= strSplitOp.Length - 1; i++)
DataRow NewDrow = dtOrdrName.NewRow();
NewDrow["Name"] = strSplitOp[i].ToString();
GvOrdr.DataSource = dtOrdrName;
Post a Comment