读取数据 用 repeater控件设好模板列就行了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public string mclass() { //数据库连接读取省略 SqlCommand cmd = new SqlCommand("select * from sclass where id=1 order by sid asc", objConnection); SqlDataReader dr = cmd.ExecuteReader(); string strBody = null; while(dr.Read()) { strBody += " " + dr["stitle"] + " <br /> "; } } <%=mclass%> 谢谢你这个方法我早用了,我现在是想用其他办法用 repeater控件设好模板列就行了我想请问下,如果用repeater呢?我GOOGLE到相关的------------------aspx文件中<asp:Repeater id="rptCategories" runat="server"> <HeaderTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="0"> </HeaderTemplate> <ItemTemplate> <!--分类名称--> <tr><th><%# DataBinder.Eval(Container.DataItem, "TypeName") %></th></tr> <!--分类下的产品--> <asp:Repeater id="rptProduct" runat="server"> <ItemTemplate> <tr><td><a href='ProductInfo.aspx?Id=<%# DataBinder.Eval(Container.DataItem, "ID") %>'><%# DataBinder.Eval(Container.DataItem, "ProductName") %></a></td></tr> </ItemTemplate> </asp:Repeater> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate></asp:Repeater>-----------aspx.cs文件中private void rptCategories_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e){ BLL.Products products =new BLL.Products(); if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rptProduct = (Repeater) e.Item.FindControl("rptProduct"); //找到分类Repeater关联的数据项 DataRowView rowv = (DataRowView)e.Item.DataItem; //提取分类ID int CategorieId = Convert.ToInt32(rowv["ID"]); //根据分类ID查询该分类下的产品,并绑定产品Repeater rptProduct.DataSource = products.GetProductsByCategorieId(CategorieId); rptProduct.DataBind(); }} 这个代码是不全的,我想请问下,如何修改代码把这个和我的数据库代码写一起呢,我是新手,请指导 首先在LOAD时给外面的REPEATER设置数据源,private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!this.IsPostBack) { BindRepeater(); BindClass(); } } private void BindRepeater() { this.bigClass.DataSource=Desay.Web.EC.Business.Stock.Default.GetBigClass(); this.bigClass.DataBind(); }private void bigClass_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater subClass = (Repeater) e.Item.FindControl("subClass"); //找到分类Repeater关联的数据项 DataRowView rowv = (DataRowView)e.Item.DataItem; //提取分类ID string CategorieId =(string)(rowv["Id"]); //根据分类ID查询该分类下的产品,并绑定产品Repeater subClass.DataSource = Desay.Web.EC.Business.Stock.Default.GetSmallClassName(CategorieId); subClass.DataBind(); } } GDI到底是什么? winform,datagridview里选中一行时,在整行下出现一条下划线来代替蓝色背景色 如何快速监控另一个命令行程序的标准输出? 一个关于define的问题, 這個為什麼報錯。 一个很简单的线程问题 请教如何使用pictureBox1显示多张图片横向排列,并由右向左滚动 问一下!!!!!!!!!!!!!!! List 转DataTable VS2013调试正常,打包生成并安装,提示连接不上数据库。 问一个古老的问题, 异常处理 To高手:子窗体调用父窗体的函数,但是函数没起作用?
{
//数据库连接读取省略
SqlCommand cmd = new SqlCommand("select * from sclass where id=1 order by sid asc", objConnection);
SqlDataReader dr = cmd.ExecuteReader();
string strBody = null;
while(dr.Read())
{
strBody += " " + dr["stitle"] + " <br /> ";
}
} <%=mclass%>
你这个方法我早用了,我现在是想用其他办法用 repeater控件设好模板列就行了我想请问下,如果用repeater呢?我GOOGLE到相关的
------------------
aspx文件中<asp:Repeater id="rptCategories" runat="server">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<!--分类名称-->
<tr><th><%# DataBinder.Eval(Container.DataItem, "TypeName") %></th></tr>
<!--分类下的产品-->
<asp:Repeater id="rptProduct" runat="server">
<ItemTemplate>
<tr><td><a href='ProductInfo.aspx?Id=<%# DataBinder.Eval(Container.DataItem, "ID") %>'><%# DataBinder.Eval(Container.DataItem, "ProductName") %></a></td></tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>-----------
aspx.cs文件中private void rptCategories_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
BLL.Products products =new BLL.Products();
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rptProduct = (Repeater) e.Item.FindControl("rptProduct");
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取分类ID
int CategorieId = Convert.ToInt32(rowv["ID"]);
//根据分类ID查询该分类下的产品,并绑定产品Repeater
rptProduct.DataSource = products.GetProductsByCategorieId(CategorieId);
rptProduct.DataBind();
}
} 这个代码是不全的,我想请问下,如何修改代码把这个和我的数据库代码写一起呢,我是新手,请指导
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
BindRepeater();
BindClass();
}
} private void BindRepeater()
{
this.bigClass.DataSource=Desay.Web.EC.Business.Stock.Default.GetBigClass();
this.bigClass.DataBind();
}private void bigClass_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater subClass = (Repeater) e.Item.FindControl("subClass");
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取分类ID
string CategorieId =(string)(rowv["Id"]);
//根据分类ID查询该分类下的产品,并绑定产品Repeater
subClass.DataSource = Desay.Web.EC.Business.Stock.Default.GetSmallClassName(CategorieId);
subClass.DataBind();
}
}