如何在不使用databinder的情况下从数据库中检索值并显示在数据列表中 [英] How to retrieve value from database and display in datalist without using databinder
本文介绍了如何在不使用databinder的情况下从数据库中检索值并显示在数据列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友
我在数据列表中的html标签
hi friends
my html tags inside datalist
<asp:Image ID="Imageitem" ImageUrl='<%# Bind("PImageName", "~/Images/{0}") %>' runat="server" />
<asp:Label ID="lblDesc" CssClass="descri" runat="server" Text='<%# DataBinder.Eval (Container.DataItem, "PDescription") %>'></asp:Label>
我必须返回数据表
如何显示数据库中的这些值.
i have to return datatable
how to display these values from database..
DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("PImageName");
dt.Columns.Add("PDescription");
for (int i = 1; i <= 16; i++)
{
dr = dt.NewRow();
dr["PImageName"] = here i need image from database
dr["PDescription"] = here i need description from database
DataList1.DataSource = dt;
DataList1.DataBind();
dt.Rows.Add(dr);
}
请朋友帮我紧急处理
please frnds help me am in urgent
推荐答案
编写如下代码.
Hi,
Write your code as below.
public void BindData()
{
DataSet ds = new DataSet();
SqlConnection con = null;
string query ="Select * From tableName";
try
{
con = new SqlConnection(connectionString);//give connection string
con.Open();
SqlCommand cmd = new SqlCommand(query,con);
SqlDataAdapter da= new SqlDataAdapter(cmd);
da.Fill(ds);
con.Close()
}
catch{}
DataList1.DataSource = ds;
DataList1.DataBind();
}
这篇关于如何在不使用databinder的情况下从数据库中检索值并显示在数据列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文