12 Replies - 17706 Views - Last Post: 03 November 2010 - 12:28 PM Rate Topic: -----

#1 staindromeo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 155
  • Joined: 21-October 10

Dynamic C# table/Div based on SQL data

Posted 21 October 2010 - 07:41 AM

Hey everyone!

I am new to C# and I have been trying to create a dynamic table/div that is based on a SQL table. If the SQL table has data in it I want the C# form table to be empty, and if it the SQL table isn't empty then I want to generate a C# table with headers and rows that will display the table's values.

Below is an example of what I am talking about:
Posted Image

Uploaded with ImageShack.us

Any help will be really appreciated. I can't seem to figure this one out. I can either create a table or a div, based on the image please tell me which route I should go with this.

The colors don't matter, I just want to get the layout right now, I can edit the colors later. This is the code I have so far. I need the code to add cells/columns to the rows.
<form id="form1" runat="server">
    <div>
        <table bgcolor="black">
                   <tr height="10px"><td colspan="3"></td></tr>
                   <tr>
                       <td align="center" valign="middle" rowspan="2"></td>
                       <td align="center" valign="bottom">Quaterly ,jhvg</td>
                       <td style="border-bottom-style: solid #000000
1px;"></td>
                   </tr>
               
                            <tr height="10px"><td colspan="3"></td></tr>
                   <tr>
                       <td align="center" valign="middle" rowspan="2"></td>
                       <td align="center" valign="bottom">Quaterly ,jhvg</td>
                       <td style="border-bottom-style: solid #000000
1px;"></td>
                   </tr>
                   

                   </table>
    </div>


Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Dynamic C# table/Div based on SQL data

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Dynamic C# table/Div based on SQL data

Posted 21 October 2010 - 07:58 AM

I believe you're thinking in a wrong way... What I would do is create XML from you table data which should be pretty easy and send this XML to web client. On the client side I would use XSLT (Extensible Stylesheet Language Transformations) which then renders your XML as html in a way defined in xsl file... You should use css file to style your table...

Another option would be to use StringBuilder and append it tag by tag and then send this string to html client.
Was This Post Helpful? 0
  • +
  • -

#3 staindromeo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 155
  • Joined: 21-October 10

Re: Dynamic C# table/Div based on SQL data

Posted 21 October 2010 - 08:05 AM

I am creating it as an ASP.NET Web Form Application in Visual Studio. The code that I have right now is ideally HTML. I just need code to draw a table as displayed in the image. I can do the rows as the code shows but I am having a hard time creating columns. I want to have a table with 3 columns and 3 rows. I can format the color of the font and cell background later.
Was This Post Helpful? 0
  • +
  • -

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Dynamic C# table/Div based on SQL data

Posted 21 October 2010 - 08:16 AM

Do you have trouble building your table layout or populating it with database values using C#?
Was This Post Helpful? 0
  • +
  • -

#5 staindromeo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 155
  • Joined: 21-October 10

Re: Dynamic C# table/Div based on SQL data

Posted 21 October 2010 - 08:20 AM

Both. But I want to approach one problem at a time. At this point I just want to get the layout like the image displayed. I am still writing a stored procedure for the data, so the SQL part doesn't matter right now. I just need the exact layout as the picture. I can create the dynamic part and just alter the visibility settings a 'False', then write a stored procedure for it, but for now I just want to get the layout.
Was This Post Helpful? 0
  • +
  • -

#6 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Dynamic C# table/Div based on SQL data

Posted 21 October 2010 - 09:24 AM

Then I suggest you post this question in HTML/CSS section on this forum...
link: http://www.dreaminco...rum/4-html-css/

When you're done with your table layout, return here in case you have any questions related to populating table cells.
Was This Post Helpful? 0
  • +
  • -

#7 staindromeo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 155
  • Joined: 21-October 10

Re: Dynamic C# table/Div based on SQL data

Posted 25 October 2010 - 07:30 PM

I built the entire layout, & I put in a connection string code to SQL in the page load section, although I am having trouble as I need to populate data into table cells (or TD's) in C#. In my layout all my tables are HTML based. So how would I point the table cells in the direction of the stored procedures of the SQL table, so that the SQL table data can populate under the HTML Table cells?
Was This Post Helpful? 0
  • +
  • -

#8 staindromeo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 155
  • Joined: 21-October 10

Re: Dynamic C# table/Div based on SQL data

Posted 29 October 2010 - 06:38 PM

I figured out that I need to use asp labels within the table data. Any ideas on how I can point the labels in the direction of the stored procedures ?

Thanks
Was This Post Helpful? 0
  • +
  • -

#9 sl4ck3r  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 285
  • Joined: 22-September 07

Re: Dynamic C# table/Div based on SQL data

Posted 29 October 2010 - 10:11 PM

why don't you use a asp:gridview? bind it to an SQL data source.
heres kinda an example: http://www.asp.net/d...ctdatasource-cs
Was This Post Helpful? 0
  • +
  • -

#10 staindromeo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 155
  • Joined: 21-October 10

Re: Dynamic C# table/Div based on SQL data

Posted 01 November 2010 - 07:37 AM

I could go the Gridview route, but is there a way to connect the ASP table as I have already created that. And even if I did do asp:gridview, I could bind it to a SQL table, but when the table has no data, how would the required message on a table being empty pop-up ? I assume I would have to do this with an IF-Then statement with the ASP:Table. I just don't know if the same concept applies to the grid view. Any ideas?
Was This Post Helpful? 0
  • +
  • -

#11 ans2007kumar  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 25-September 09

Re: Dynamic C# table/Div based on SQL data

Posted 01 November 2010 - 08:32 AM

Actually it is quit easy to create the entire stuff you said i have used in my project to here is a short example.

Table tb= new Table();//create table
TableRow tr= new TableRow();
TableCell tc=new TableCell();
Label l=new Lable();
l.Text=;//populate from db
tc.Controls.Add(l);
tr.Cells.Add(tc);
tb.Rows.Add(tr);

that's it put the code in if loop to check the data in db or not and then you go and put a while loop too ok.
___________________________________________________
Mark it useful if really help contact at [email protected] if you need more help.

This post has been edited by ans2007kumar: 01 November 2010 - 08:37 AM

Was This Post Helpful? 0
  • +
  • -

#12 staindromeo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 155
  • Joined: 21-October 10

Re: Dynamic C# table/Div based on SQL data

Posted 01 November 2010 - 11:08 AM

I'll try this method & see what I get, although keep in mind I am populating data through a stored procedure and not a SELECT statement in SQL. I changed up the other HTML table and made it an ASP table as well. So now I have 2 ASP:Tables. I assume that I will have to play with the visibility settings based on which of the two tables should show up based on IF the SQL table has data in it or not.
Was This Post Helpful? 0
  • +
  • -

#13 staindromeo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 155
  • Joined: 21-October 10

Re: Dynamic C# table/Div based on SQL data

Posted 03 November 2010 - 12:28 PM

[quote name='ans2007kumar' date='01 November 2010 - 07:32 AM' timestamp='1288625568' post='1155865']
Actually it is quit easy to create the entire stuff you said i have used in my project to here is a short example.

Table tb= new Table();//create table
TableRow tr= new TableRow();
TableCell tc=new TableCell();
Label l=new Lable();
l.Text=;//populate from db
tc.Controls.Add(l);
tr.Cells.Add(tc);
tb.Rows.Add(tr);

that's it put the code in if loop to check the data in db or not and then you go and put a while loop too ok.
___________________________________________________{/quote]

I am having trouble with this code. Is it possible to hide/show the tables based on if it has data in it in a particular row in one of the table. So this would be If Table 1's row has data in its cells then Hide Table 2 & if the Row in Table 1 doesn't have data then to hide Table 1 & only show Table 2. Is this possible?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1