Click here to Skip to main content
15,886,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
From date:one text box
To date:one text box
taken .
after that i have taken one Submit Button. on clicking Submit Button I have to get Dynamic table within the Range of Dates i entered like a calender.Please Answer this.......
Posted
Updated 20-May-12 19:54pm
v2
Comments
Prasad_Kulkarni 21-May-12 1:42am    
What does that within the from date and to date means?
[no name] 21-May-12 2:12am    
your question is not clear and also show code what you had done for this.

From the namespace System.Data DataTable DataColumn classes we can easily create table dynamically in C# and also in ASP.NET.

C#
using System.Data;

// Create a DataTable instance
DataTable dTbl = new DataTable("myDynamicTable");

// Create a DataColumn instances

DataColumn dValue = new DataColumn();
DataColumn dMember = new DataColumn();

dValue.ColumnName = "Id";
dValue.DataType = Type.GetType("System.Int32");

dMember.ColumnName = "Name";
dMember.DataType = Type.GetType("System.String");

// Add these DataColumns into the DataTable

dTbl.Columns.Add(dValue);
dTbl.Columns.Add(dMember);


After you create table dynamically, you can add rows into it.
It is a good way to create DataRow from the table we create, with the function NewRow().

C#
// Create a DataRow Instance from the table we create above, with NewRow();

DataRow myrow = dTbl.NewRow();

myrow["Id"] = 1;
myrow["Name"] = "Tux";

// Add the row into the table

dTbl.Rows.Add(myrow);


That's all for creating table dynamically in C# and also ASP.NET.
 
Share this answer
 
Comments
Prasad_Kulkarni 21-May-12 2:06am    
Krish, I din't used dtValue anywhere in my solution, are you talking about Technoses' solution?
m v krish 21-May-12 2:10am    
It is about Technoses's solution.
From the namespace System.Data DataTable DataColumn classes we can easily create table dynamically in C# and also in ASP.NET .


C#
DateTime dt1 = new DateTime(2012, 5, 1);//  From Date
DateTime dt2 = DateTime.Now;    // To Date

DataTable tbl = new DataTable("myTbl");
tbl.Columns.Add("dtValue", typeof(DateTime));

while (dt1 < dt2)
{
    tbl.Rows.Add(dt1.ToString("dd-MMM-yyyy"));
    dt1.AddDays(1);
}
 
Share this answer
 
Comments
m v krish 21-May-12 2:05am    
what is "dtvalue" in the solution given..
Technoses 21-May-12 12:12pm    
this is column name in data table
This may help you,
Check this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900