C# 在*.aspx页面中显示数组元素

C# 在*.aspx页面中显示数组元素,c#,asp.net,arrays,C#,Asp.net,Arrays,对于你们中的一些人来说,这可能看起来微不足道——但请允许我这样做,因为我在理解如何显示数组元素时似乎有严重的思维障碍 好的,这就是我的观点: <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCoding._Default" %> <asp:Conten

对于你们中的一些人来说,这可能看起来微不足道——但请允许我这样做,因为我在理解如何显示数组元素时似乎有严重的思维障碍

好的,这就是我的观点:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCoding._Default" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1><%: Title %>.</h1>
                <h2>Modify this template to jump-start your ASP.NET application.</h2>
            </hgroup>
            <p>
                <asp:TextBox ID="post_feedback" runat="server" Height="100" Width="500" BackColor="#0066FF" Font-Bold="True" ForeColor="#FF9933" Wrap="False" TextMode="MultiLine" BorderColor="#000099" BorderStyle="Groove" BorderWidth="2"></asp:TextBox>  
        <br />
        <asp:Button ID="Count_Sentences" runat="server" Text="Count Sentences" OnClick="Count_Sentences_Click"/>

        <br />
        <br />

        <asp:Label ID="Num_Sentences" runat="server" Font-Bold="true">How Many Sentences Do we have today?</asp:Label>

            </p>
        </div>
    </section>
 </asp:Content>

.
修改此模板以跳转启动ASP.NET应用程序。




今天我们有几个句子?

和Default.aspx.cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TestCoding
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Count_Sentences_Click(object sender, EventArgs e)


        {

            int post_length = post_feedback.Text.Length;

            string[] post_words = post_feedback.Text.Split(' ');
            int num_words = post_words.Length;



            Num_Sentences.Text = post_feedback.Text + " " + Convert.ToString(post_length) + " and has " + post_words.Length + " words." + post_words[0];
            for (int i = 0; i < num_words; i++)
            {
                Console.WriteLine(post_words[i]);
            }

        }


    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
命名空间测试编码
{
公共部分类\u默认值:第页
{
受保护的无效页面加载(对象发送方、事件参数e)
{
}
受保护的无效计数\u语句\u单击(对象发送者,事件参数e)
{
int post_length=post_feedback.Text.length;
string[]post_words=post_feedback.Text.Split(“”);
int num_words=post_words.Length;
Num_-concements.Text=post_-feedback.Text+“”+Convert.ToString(post_-length)+”并具有“+post_-words.length+”单词。“+post_-words[0];
for(int i=0;i
好的,我知道Num_句子是我在aspx页面中创建的一个标签-点击按钮,就会调用Count_句子\u Click例程,它会做一些“填充”,并将Num_句子.Text绑定到一个由不同字符串和其他数据组成的字符串

数据绑定之后的代码位,我打算让post_单词数组中的所有元素都被编写出来……但效果不太好

到目前为止,我所发现的似乎是,“哦,你所要做的就是建立一个排序循环,只需执行Console.WriteLine(arrayname[I]),一切都会与宇宙融为一体。”


显然,我在理解如何成功显示数组元素时遇到了一些问题。我需要一个单独的标签ID来把它放进去吗?我很困惑P

控制台。WriteLine
写入控制台。网页不是控制台。查看基于给定项集合“重复”标记节的控件:Repeater、ListView等Hanks CyberDude-找到了一个适合我的解决方案。:)