我需要将我的 SQL 字段绑定到我的 Gridview 列。我前一阵子做了这个,效果很好,但我忘了怎么做,所以我让 ASP.NET 自动生成列并且它可以工作,现在我想控制数据绑定,下面是我的代码和我的 Gridview。 ..任何帮助将不胜感激。
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(Sitecore.Configuration.Settings.GetConnectionString("feedback"));
SqlCommand cmd = new SqlCommand("select * from fb_results", conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conn.Close();
}
网格视图:
<head id="Head1" runat="server">
<title>Feedback</title>
</head>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="rpt_login" HeaderText="User Id" />
<asp:BoundField DataField="fb_url" HeaderText="URL___" />
<asp:BoundField DataField="fb_response" HeaderText="Answer: Did you find what you were looking for?" />
<asp:BoundField DataField="fb_noResponse" HeaderText="No Response or Ignore" />
<asp:BoundField DataField="fb_date" HeaderText="Date" />
<asp:BoundField DataField="fb_serviceCall" HeaderText="Prevented Service Call" />
<asp:BoundField DataField="fb_partsShipment" HeaderText="Prevented Parts Shipment" />
<asp:BoundField DataField="fb_warranty" HeaderText="Under Warranty" />
<asp:BoundField DataField="fb_cancel" HeaderText="Cancelled" />
<asp:BoundField DataField="fb_none" HeaderText="None of the Above" />
</Columns>
</asp:GridView>