gpt4 book ai didi

c# - 在 asp.net c# 4.0 中完全以编程方式创建 Gridview

转载 作者:行者123 更新时间:2023-12-02 17:51:17 25 4
gpt4 key购买 nike

我想创建多个 GridView 。我想从代码隐藏(.cs)文件中添加它们。这是我的代码,几乎已经工作了。但有人能找出这有什么问题吗?

示例.aspx:

    <body>
<form id="form1" runat="server">
<%CreateGridView();%>
</form>
</body>

示例.aspx.cs:

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

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected GridView CreateGridView()
{
GridView gv = new GridView();
gv.ID = "_gridview1";
Queue q = new Queue();
for (int i = 0; i < 20; i++)
q.Enqueue(i);
gv.DataSource = q;
gv.DataBind();
gv.Visible = true;
return gv;
}
}

最佳答案

示例.aspx:

<body>
<form id="form1" runat="server">
<asp:PlaceHolder id="ph" runat="server"/>
</form>
</body>

示例.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 20; i++)
{
GridView gv = new GridView();
gv.ID = "_gridview" + i;
Queue q = new Queue();
q.Enqueue(i);
gv.DataSource = q;
gv.DataBind();
ph.Controls.Add(gv);
}
}

关于c# - 在 asp.net c# 4.0 中完全以编程方式创建 Gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12160108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com