There are various methods to populate a DataTable Tag in CodeBehind. One approach involves creating a DataTable class variable, adding rows and columns to it, and then assigning the variable to the Tag.
Please find below a code snippet that demonstrates the process. In this example, we create a DataTable object called “Table1” and add two columns (“Name” and “Age”) to it. Next, we create a DataRow object named “row1” and assign values to the “Name” and “Age” columns of that row. Finally, we add the row to the Table1 DataTable, and the @Tag.Table1 is assigned the Table1 object:
DataTable Table1 = new DataTable();
DataColumn Name = new DataColumn();
DataColumn Age = new DataColumn();
Name.ColumnName = "Name";
Age.ColumnName = "Age";
Table1.Columns.Add(Name);
Table1.Columns.Add(Age);
DataRow row1 = Table1.NewRow();
row1["Name"] = "Hung";
row1["Age"] = "25";
Table1.Rows.Add(row1);
@Tag.row_count = Table1.Rows.Count;
@tag.column_count = Table1.Columns.Count;
@Tag.Table1 = Table1;
You can achieve similar results using Queries or by modifying the DataGrid itself. Please let us know if you require further assistance in those areas.
On the code section we sent you, the rows and columns are being added to the DataTable Tag, the way we do that, is by adding the desired data to a DataTable variable on CodeBehind, and on the last line of the code (@Tag.Table1=Table1;) we assigned the DataTable class variable to the DataTable Tag.
This way, all the columns and rows added in the code are going to the DataTable Tag.
Please let us know if you still have any questions regarding Datatable Tags.
Dear Sir
Thank for your Feedback.
As I share. In My project I want to work directly with Datatable Tag ( without Datatable Class Varriable).
I create a Script in code behind with no error when complie. But when runtime, i monitored via trace window. The error was shown.
Please see below pictures