How to build a swap mesh view without a data source

I want to ask a question about how to do swap in ASP.net encoding using C #.

the thing I'm trying to do is that I want to display some content, have multiple columns and multiple rows.

in the code itself, I have a list of objects, let's say Object A

class A {
   integer id;
   string name;
   string desc;
}

and want to display it on a page with available features.

I do a search on Google, ASP.net offers gridview and listview, but they all require a data source, which means the table is directly bound to the database.

This is not what I want, because my list of A objects comes from some other, and not from my database (for example, this is a composite set of data that is generated at runtime)

so that I can still use these benifit components, or should I do it all on my own to swap ???

THX

+3
source share
2 answers

The DataSource property will also take the value List<>or BindingList<>.

To use this in code:

protected void Page_Load(object sender, EventArgs e)
{
    var data = new List<Sample>();
    data.Add (...);

    GridView1.DataSource = data;
    GridView1.DataBind();
}

And maybe some IsPostback logic, etc.

+3
source

My advice is to use a GridView with which you can use an ObjectDataSource object that can take its basic data from the class method you specify. So the class method could be (after your code example):

public static List<A> GetAllAs()
{
    return myAs;
}

and your aspx page will contain

<asp:ObjectDataSource ID="MyODS" runat="server" TypeName="Namespace.Classname" SelectMethod="GetAllAs" />

<asp:GridView ID="grdMyGridView" runat="server" DataSourceID="MyODS" AllowPaging="True" ... >

TypeName SelectMethod ObjectDataSource , ODS . AllowPaging="True" GridView .

+6

Source: https://habr.com/ru/post/1721176/


All Articles