0

我正在制作一个愿望清单,将列表 ID 作为 id1、id2、id5 等保存到 SQL 中。

我正在尝试使用 Array 对 SQL 进行 ListingID = id1, ListingID = id2... 调用,以便它在一页上显示所有列表。

我可以为此使用带有 Array 的 Repeater/ListView 吗?

抱歉,如果这不是很清楚,我对此很陌生。我已经做了一个小时左右的研究,但对我来说并不奏效。

感谢您的考虑。

4

3 回答 3

0

是的可以使用

    protected void Page_Load(object sender, EventArgs e)
    {
        string test = "s1,s2,s3";
        string[] StrArray = test.Split(',');

        if (!Page.IsPostBack)
        {
            rptTest.DataSource = StrArray;
            rptTest.DataBind();
        }
    }


    <asp:Repeater runat="server" ID="rptTest"> 
        <ItemTemplate>
        listingID = <%# Container.DataItem %>
        </ItemTemplate>
    </asp:Repeater>
于 2013-08-17T06:02:57.537 回答
0

您可以像这样将数组绑定到 datagridview

顺便说一句,您的 gridview 将如下所示

<asp:GridView ID="gView" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="ValueToBind" />
    </Columns>
</asp:GridView>

做一堂课

public class ValuesToBind
{
    public string ValueToBind { get; set; }
}

List<ValuesToBind> lstToBind = (
    from ar in yourArray
    select new ValuesToBind
    {
        ValueToBind = ar
    }).ToList();
gView.DataSource = lstTobind;
gView.DataBind();
于 2013-08-17T06:06:05.270 回答
0

Listing如果您创建一个包含您想要在转发器/列表视图/网格视图中显示的信息的类,您会更好,如下所示:

public class Listing
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }

    // And whatever else you want to display to the user and that exists in the database
}

现在,您可以构建一个List<Listing>用作数据绑定 ASP.NET 控件(中继器、列表视图、网格视图等)的数据源,如下所示:

var listOfListings = new List<Listing>();
listOfListings = GetListingsFromDatabase();

GridView.DataSource = listOfListings;
GridView.DataBind();
于 2013-08-17T06:01:59.207 回答