Jump to content

Having trouble loading a image and some text from sql server database and display in ASP webpage

i want to display a image and some text from my database when my web page loads.i have tried the code below so far to practice but it hasnt worked.i couldnt still identify what is wrong.what could be the problem?

----------------------------------------------------------Page1.aspx------------------------------------------------------------    

<form id="form2" runat="server">
   <div>
       <asp:DataList ID="DataList2" runat="server">
    <ItemTemplate>
    <table>
       
       <tr>
          <td>
            <img src="<%#Eval("image") %>" height="500" width="100" />
          </td>
    
          <td>
            <%#Eval("des") %>
          </td>
         </tr>

    </table>
     </ItemTemplate>
     </asp:DataList>
    </div>
  -----------------------------------------------------------------------------------------------------------------------------
  
  ---------------page1.aspx.cs----------------------------------------------------------------------------------
  
          protected void Page_Load(object sender, EventArgs e)
        {
            cn.Open();
            SqlCommand cmd = cn.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from products";
            cmd.ExecuteNonQuery();
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            DataList1.DataSource = dt;
            DataList1.DataBind();
            cn.Close();
  }
  
  ---------------------------------------------------------------------------------------------------------------------------
  

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×