新问题。我有这个作为我的网格视图,我想要它,所以当页面加载时,网格视图充满了数据库信息。
下面是gridview的代码。下面是c#代码。
更新
<asp:GridView ID="RegistrantsView" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="True"
CellPadding="4"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
C#:
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["FFL-New DataConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
connection.Open();//opens connection on page load
SqlCommand selectAllCommand = new SqlCommand();
selectAllCommand.CommandText = "select * from registrants";
selectAllCommand.Connection = connection;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = selectAllCommand;
DataTable dt = new DataTable();
sda.Fill(dt);
RegistrantsView.DataSource = dt;
RegistrantsView.DataBind();
}