这是我的代码来绑定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
您确定您查询的表格中有数据吗? –