Hiiiiiiii,
How to dynamically create table in c# language with windows application form based on datatable value?
plz give me example with code.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question.
Jeetendra GundPosted Sep 16, 2013, 7:44 AM
try this code,
Regards,
Jeetendra
Suthish NairPosted Sep 11, 2013, 9:28 AM
DataGridView - Insert, Update, Delete and Retrieve records using stored procedure
http://www.codeproject.com/Articles/23640/How-to-send-DataGridView-contents-by-email
http://stackoverflow.com/questions/16547588/sending-datagridview-to-email
selva kumarPosted Sep 11, 2013, 6:54 AM
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default4 : System.Web.UI.Page
{
private int numOfRows = 0;
private int numOfColumns = 0;
protected void Page_Load(object sender, EventArgs e)
{
// the two paramters are declared globally
GenerateTable(numOfColumns, numOfRows);
}
protected void Button1_Click(object sender, EventArgs e)
{
//Check if the inputs are numbers
if (int.TryParse(TextBox1.Text.Trim(), out numOfColumns) && int.TryParse(TextBox2.Text.Trim(), out numOfRows))
{
//Generate the Table based from the inputs
GenerateTable(numOfColumns, numOfRows);
//Store the current Rows and Columns In ViewState as a reference value when it post backs
ViewState["cols"] = numOfColumns;
ViewState["rows"] = numOfRows;
}
else
{
Response.Write("Values are not numeric!");
}
}
private void GenerateTable(int colsCount, int rowsCount)
{
//Creat the Table and Add it to the Page
Table table = new Table();
table.ID = "Table1";
Page.Form.Controls.Add(table);
// Now iterate through the table and add your controls
for (int i = 0; i < rowsCount; i++)
{
TableRow row = new TableRow();
for (int j = 0; j < colsCount; j++)
{
TableCell cell = new TableCell();
TextBox tb = new TextBox();
// Set a unique ID for each TextBox added
tb.ID = "TextBoxRow_" + i + "Col_" + j;
// Add the control to the TableCell
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
// Add the TableRow to the Table
table.Rows.Add(row);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//Check if ViewState values are null
if (ViewState["cols"] != null && ViewState["rows"] != null)
{
//Find the Table in the page
Table table = (Table)Page.FindControl("Table1");
if (table != null)
{
//Re create the Table with the current rows and columns
GenerateTable(int.Parse(ViewState["cols"].ToString()), int.Parse(ViewState["rows"].ToString()));
// Now we can loop through the rows and columns of the Table and get the values from the TextBoxes
for (int i = 0; i < int.Parse(ViewState["rows"].ToString()); i++)
{
for (int j = 0; j < int.Parse(ViewState["cols"].ToString()); j++)
{
//Print the values entered
if (Request.Form["TextBoxRow_" + i + "Col_" + j] != string.Empty)
{
Response.Write(Request.Form["TextBoxRow_" +i+ "Col_" + j] +"
");
}
}
}
}
}
}
}
Iftikar HussainPosted Aug 27, 2013, 4:11 AM
ranjan sahooPosted Aug 27, 2013, 4:05 AM
Iftikar HussainPosted Aug 27, 2013, 3:43 AM
ranjan sahooPosted Aug 27, 2013, 3:40 AM
Iftikar HussainPosted Aug 27, 2013, 3:37 AM
ranjan sahooPosted Aug 27, 2013, 3:35 AM
Iftikar HussainPosted Aug 27, 2013, 3:33 AM
ranjan sahooPosted Aug 27, 2013, 3:29 AM
Iftikar HussainPosted Aug 27, 2013, 3:23 AM
ranjan sahooPosted Aug 27, 2013, 3:22 AM
Iftikar HussainPosted Aug 27, 2013, 3:16 AM
ranjan sahooPosted Aug 27, 2013, 3:07 AM
Iftikar HussainPosted Aug 27, 2013, 3:02 AM
ranjan sahooPosted Aug 27, 2013, 3:00 AM
Iftikar HussainPosted Aug 27, 2013, 2:58 AM
ranjan sahooPosted Aug 27, 2013, 2:56 AM
Iftikar HussainPosted Aug 27, 2013, 2:51 AM
Regards,
Iftikar
ranjan sahooPosted Aug 27, 2013, 2:46 AM
Iftikar HussainPosted Aug 27, 2013, 2:38 AM
Regards,
Iftikar
ranjan sahooPosted Aug 27, 2013, 2:37 AM
Iftikar HussainPosted Aug 27, 2013, 2:36 AM
ranjan sahooPosted Aug 27, 2013, 2:34 AM
Iftikar HussainPosted Aug 27, 2013, 2:32 AM
Sanjeeb LenkaPosted Aug 27, 2013, 2:31 AM
you can use datagridview control of windows form to show your data in tabular format.
ranjan sahooPosted Aug 27, 2013, 2:30 AM
Jaganathan BantheswaranPosted Aug 27, 2013, 2:25 AM
The above link explains the bulk copy to SQL.
Iftikar HussainPosted Aug 27, 2013, 2:10 AM
Are asking for creating DataTable?
Regards,
Iftikar