.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
abhays
Clintonzz
arronlee
mattyclown
cathyhill345

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Binding textbox value to a column in datatable in asp.net

Posted By: Naresh     Posted Date: December 12, 2009    Points:2   Category :ASP.Net
hi,
how to bind the values from text boxes after a button click to a datatable in asp.net using C# coading

Responses
Author: Amit Mehra               
Posted Date: December 12, 2009     Points: 5   

Hi Malathy,

To add the textbox control value to a dataTable you can try like this.

//Your DataTable
DataTable myDataTable = new DataTable();

DataColumn myDataColumn;

myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "id";
myDataTable.Columns.Add(myDataColumn);

myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "username";
myDataTable.Columns.Add(myDataColumn);

//Now to add the TextBox value in a row column

DataRow row;

row = myTable.NewRow();

row["id"] = Guid.NewGuid().ToString();
row["username"] = TextBox1.Text;// Here you are assigning the value

myTable.Rows.Add(row); //Add the row to a table


Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend