Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net gridview数据绑定不工作_Asp.net_Gridview - Fatal编程技术网

Asp.net gridview数据绑定不工作

Asp.net gridview数据绑定不工作,asp.net,gridview,Asp.net,Gridview,这是我绑定gridview的代码。但当我运行时,我看不到任何东西,没有gridview,只有空的,但当我使用sqldatsource时,我可以绑定所有内容。 我怎样才能解决这个问题 SqlConnection conn = new SqlConnection(yol); conn.Open(); SqlCommand komut = new SqlCommand("select * from duyuru", conn); SqlDataReader dr

这是我绑定gridview的代码。但当我运行时,我看不到任何东西,没有gridview,只有空的,但当我使用sqldatsource时,我可以绑定所有内容。 我怎样才能解决这个问题

 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>
试试这个:

SqlConnection conn = new SqlConnection(yol);

        conn.Open();

    SqlCommand komut = new SqlCommand("select * from duyuru", conn);

SqlDataAdapter adapter = new SqlDataAdapter(komut);
            DataSet ds = new DataSet();

             adapter.Fill(ds, "Products");//here enter your table name

            GridView1.DataSource = ds;
            GridView1.DataBind();

你也可以添加你的GridView代码吗?你确定你查询的表中有数据吗?ofc,我确定我可以绑定sqldatasource和DataSource,但我不能绑定代码!我试过很多次,但都不起作用,我不知道为什么?关于vs2008的一切?