gpt4 book ai didi

c# - 如何使用 gridview 在 .aspx 页面中显示信息

转载 作者:太空宇宙 更新时间:2023-11-03 14:07:24 24 4
gpt4 key购买 nike

我是 C# 的新手,不知道如何使用 C# gridview 显示并在我的 .aspx 页面中显示。你如何编码?下面是我做的代码,但我需要一些建议是否正确。

这是我在 .aspx 页面中的代码

<asp:GridView ID="WorkshopEnrolled" runat="server"
AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="WorkshopEnrolledDataSource" EnableViewState="False">
<Columns>
<asp:BoundField DataField="WorkshopCode" HeaderText="Workshop Code"
SortExpression="WorkshopCode" />
<asp:BoundField DataField="WorkshopName" HeaderText="Workshop Name"
HtmlEncode="False" SortExpression="WorkshopName">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="WorkshopDate"
HeaderText="Workshop Date" SortExpression="WorkshopDate">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="WorkshopLocation"
HeaderText="Workshop Location" SortExpression="WorkshopLocation">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
</Columns>

这是我的 .aspx.cs 文件

public partial class Workshop : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie httpCookie = Request.Cookies["TeamAwesomeCookie"];

if (httpCookie != null)
{
// Write code to update photo filename in Users' table
WorkshopController wc = new WorkshopController();
ArrayList workshopEnrolled = wc.retrieveWorkshopByStudent(int.Parse(httpCookie.Values["UserID"]));
ArrayList availableWorkshop = wc.retrieveAvailableWorkshops();

}

}


protected void WorkshopEnrolled_RowDataBound(object sender, GridViewRowEventArgs e)
{
//string workshopCode = null;
// string workshopName = null;
// string workshopDate = null;
// string workshopLocation = null;

if (e.Row.RowType == DataControlRowType.DataRow)
{
// Reference the ProductsRow via the e.Row.DataItem property
Workshop workshopEnrolled = (Workshop)e.Row.DataItem;


}
}


}

最佳答案

乍一看,您的代码看起来不错,只是您忘记了对网格进行数据绑定(bind),而且您的意图似乎是从后面的代码绑定(bind)数据。话虽如此,删除

 DataSourceID="WorkshopEnrolledDataSource" 

从标记中,将这些行添加到后面的代码中,在 2 个 ArrayList 声明下方:

 WorkshopEnrolled.DataSource=          workshopEnrolled ;
WorkshopEnrolled.DataBind();

关于c# - 如何使用 gridview 在 .aspx 页面中显示信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8960211/

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