简体   繁体   中英

How to populate FormView from SQLDataReader object?

I am new to ASP.NET and C#. I am trying to display some basic information about a "supplier" which is retrieved from a database with a simple query. I started off using a GridView, and it worked perfectly fine, but I like the look of FormView more. The problem is nothing is displaying in the FormView... it is invisible.

Here is the C# code:

connection = new SqlConnection(connectionInfo);
connection.Open();

SqlCommand cmd = new SqlCommand("select... from... where...");
SqlDataReader supplierReader = cmd.ExecuteReader();

supplierForm.DataSource = supplierReader;
supplierForm.DataBind();

supplierReader.Close();
connection.Close();

And here is the ASP code:

<asp:FormView ID="supplierForm" runat="server">
    </asp:FormView>

This is for a class project, so I am not asking you to solve the problem for me. If somebody could just point me in the right direction, that would be great :)

your binding seems correct.

Nevertheless you are missing the binding/markup to display the data in your page - how to do that You might wanna check out these links: MSDN Tutorial for Formview and FormView Control: Step by Step .

Greetz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM