Wednesday, November 28, 2012

String to DataTable in asp.net using C#.Net

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

Description:
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.

Examples:
Some  examples for JQuery Auto complete text boxhow to bind or Export CSV data to data table in asp.net.The 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>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:GridView ID="GvOrdr" runat="server"></asp:GridView>
</asp:Content>

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();
dtOrdrName.Rows.Add(NewDrow);
}
GvOrdr.DataSource = dtOrdrName;
GvOrdr.DataBind();
Post a Comment

Bel