如何动态地在ASP.NET行添加到表? [英] How to dynamically add rows to a table in ASP.NET?

查看:142
本文介绍了如何动态地在ASP.NET行添加到表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,今天我开始学习ASP.NET。不幸的是我没有发现任何好的教程在网上,我买不起的那一刻买书,所以我必须创建在Visual Studio 2010中的ASP.NET Web应用程序,只是玩的默认项目设置

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.

到目前为止,这是我在我的Default.aspx:

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>

我创建的标题行已经有一个简单的表格。通过C#剧本,我希望能够动态地行添加到这个HTML表。这是ASP.NET思维的正确方法?如果是这样,我怎么能做到这一点?我敢肯定,我需要一个添加按钮,添加一个新行到表,与可编辑的字段,以及提交按钮,增加了一些东西到数据库。

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.

先谢谢了。

推荐答案

你有没有尝试在ASP:表

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>  

为您创建它们并将它们添加到myTable.Rows需要在脚本中可以再加入行

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);

由于你的问题的描述,虽然,我说你会更好使用一个GridView或Repeater由@Kirk沃尔提及。

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:

斯科特Guthrie的博客

4,距离Rolla家伙

MSDN

code项目Asp.Net

Scott Guthrie's Blog
4 Guys from Rolla
MSDN
Code Project Asp.Net

这篇关于如何动态地在ASP.NET行添加到表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆