MongoDB and C # Resources

I am using MongoDB with a C # driver. I managed to add / remove / update data from collections, but I do not know how to display the collection in gridview. If this is not possible, how can I display collections as tables in asp.net?

+4
source share
1 answer

First download the request from mongodb as follows:

var server = MongoServer.Create("mongodb://localhost:27020"); var database = server.GetDatabase("someDb"); var collection = database.GetCollection<User>("someCollection"); var searchQuery = Query.EQ("someName", "someValue"); // you can place any search condition here //if you want all documents from collection use FindAll var cursor = collection.Find(searchQuery); cursor.SetLimit(50); // you can specify limit // set sort orders cursor.SetSortOrder(SortBy.Ascending("someSorField").Descending("someSorField2")); var resultList = cursor.ToList(); //get list of items from mongodb 

Then, in the Page_Load event, bind the data:

  gvwExample.DataSource = resultList; gvwExample.DataBind(); 

Then specify the data source binding on the page:

 <asp:GridView ID="gvwExample" runat="server" AutoGenerateColumns="False" CssClass="basix" > <columns> <asp:BoundField DataField="FirstName" HeaderText="First Name" /> <asp:BoundField DataField="LastName" HeaderText="Last Name" /> </columns> </asp:GridView> 
+8
source

All Articles