Hello
A simple code is like this:
in your html or aspx page (front end):
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4">
<ItemTemplate>
Product Name:
<asp:Label ID="lblPName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
<br />
Product Price:
<asp:Label ID="lblPPrice" runat="server" Text='<%# Eval("ProductPrice") %>'></asp:Label>
<br />
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
and in aspx.cs or your back end page:
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=SPIDER;Initial Catalog=Product;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
protected void BindData()
{
DataSet ds = new DataSet();
DataTable FromTable = new DataTable();
conn.Open();
string cmdstr = "Select * from Products";
SqlCommand cmd = new SqlCommand(cmdstr, conn);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
}
}