So today I started learning ASP.NET. Unfortunately I haven't found any good tutorials online, and I can't afford to buy books at the moment, so I've had to create a ASP.NET web application in Visual Studio 2010 and just play around with the default project setup.
So far here's what I have in my Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._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>Project Management</title> </head> <body> <div style="padding-bottom:10px;"> Project Management System</div> <div> <table style="width:100%;"> <tr> <td>Name</td> <td>Task</td> <td>Hours</td> </tr> </table></div> </body> </html>
I created a simple table with the header row already in there. Through a C# script, I want to be able to dynamically add rows to this HTML table. Is this the right way of thinking in ASP.NET? If so, how can I do this? I'm sure I'll need an "Add" button, which adds a new row to the table, with editable fields, and a "submit" button which adds some stuff to a database.
Basically just a rundown of how this is done would be ever so helpful. Also if anyone knows any good tutorials or websites that can help me out with things like this, please let me know.
Thanks in advance.
BorderStyle = BorderStyle. Solid; tb.ID = "myTable"; foreach (Student student in studentList) { TableRow tr = new TableRow(); TableCell tc1 = new TableCell(); TableCell tc2 = new TableCell(); TableCell tc3 = new TableCell(); TableCell tc4 = new TableCell(); TableCell tc5 = new TableCell(); tc1.
You can add row just by using: TableRow row1=new TableRow(); TableRows. add(row1);
Have you attempted the Asp:Table?
<asp:Table ID="myTable" runat="server" Width="100%"> <asp:TableRow> <asp:TableCell>Name</asp:TableCell> <asp:TableCell>Task</asp:TableCell> <asp:TableCell>Hours</asp:TableCell> </asp:TableRow> </asp:Table>
You can then add rows as you need to in the script by creating them and adding them to myTable.Rows
TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = "blah blah blah"; row.Cells.Add(cell1); myTable.Rows.Add(row);
Given your question description though, I'd say you'd be better off using a GridView or Repeater as mentioned by @Kirk Woll.
EDIT - Also, if you want to learn without buying books here are a few sites you absolutely need to become familiar with:
Scott Guthrie's Blog
4 Guys from Rolla
MSDN
Code Project Asp.Net
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With