Forum guidelines
  • Home
  • »
  • .NET 5.0
  • »
  • Need code for Auto generating colums on depending records
AuthorQuestion
Need code for Auto generating colums on depending records
Posted on: 17 Feb 2012
Here i need code for generating Number of rows and Columns without using grid view .it should generating rows and columns on depending upon records in the database.
For example it should generate 2 rows and 2columns if database contains  2 rows and 2columns of records same 3 rows and 3columns if database contains 3 rows and 3columns of records depending upon records it should display.here we should use only table with rows
for 2rows and 2columns
record
it should create
<table>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<td>
</td>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>



AuthorReply
Re: Need code for Auto generating colums on depending records
Posted on: 17 Feb 2012  
display data using table control.rar Hi Raghu,


Try this...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Display_Data_Using_Table_Control._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server"
            Text="Display Records Through table control" onclick="Button1_Click" />
    <asp:Table ID="Table1" runat="server" BackColor="#FFFF80" BorderColor="#FF8080"
        BorderStyle="Solid" BorderWidth="5px" ForeColor="Red" GridLines="Both">
    </asp:Table><br />
    </div>
    </form>
</body>
</html>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_Data_Using_Table_Control
{
    public partial class _Default : System.Web.UI.Page
    {
        string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        string str;
        SqlCommand com;
        SqlDataAdapter sqlda;
        DataSet ds;
        DataTable dt;
        int i;
        int j;

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(strConnString);
            try
            {
                con.Open();
                str = "select * from student ";
                com = new SqlCommand(str, con);
                ds = new DataSet();
                sqlda = new SqlDataAdapter(com);
                sqlda.Fill(ds, "student");
                dt = ds.Tables["student"];

                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    TableRow tr = new TableRow();

                    for (j = 0; j <= dt.Columns.Count - 1; j++)
                    {
                        TableCell tc = new TableCell();
                        tc.Text = dt.Rows[i].ItemArray[j].ToString();
                        tr.Cells.Add(tc);
                        Table1.Rows.Add(tr);
                    }
                }
                con.Close();

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

        }
    }
}


Thanks
If this post helps you mark it as answer

If this post helps you mark it as answer
Thanks

Re: Need code for Auto generating colums on depending records
Posted on: 19 Feb 2012  
There are lots of light weighted control available in VS, which renders into tables..
Mark as Answer, on the posts reply's that helped you !!!.
Re: Need code for Auto generating colums on depending records
Posted on: 24 Feb 2012  
If this post helps you mark it as answer

Thanks

If this post helps you mark it as answer
Thanks

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.