這是我的代碼來綁定gridview。但是當我運行時,我什麼都看不到(沒有gridview只是空的),但是當我使用sqldatsource時,我可以綁定所有的。 我該如何解決這個問題?gridview dataBind不工作
SqlConnection conn = new SqlConnection(yol);
conn.Open();
SqlCommand komut = new SqlCommand("select * from duyuru", conn);
SqlDataReader dr = komut.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
conn.Close();
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowdeleting="GridView1_RowDeleting" AllowPaging="True"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" onrowcommand="GridView1_RowCommand">
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
你可以添加你的GridView的代碼呢? – dgarbacz
已添加html代碼 – Acablack
您確定您查詢的表格中有數據嗎? –