Repeater的复杂使用讲解实例子
2008-04-16 17:59
549 查看
Repeater的复杂使用讲解实例子
在CSDN上看到大家问这到这种贴子,晚上回家想了下大概做下了
![](http://p.blog.csdn.net/images/p_blog_csdn_net/cefriend/2.gif)
做得不完全,给大家一种思想吧(用到的嵌套Repeater控件)有些出入,楼主可自已再改动下,
http://topic.csdn.net/u/20080414/22/b54c735c-b2c0-4225-9a25-080d1309b168.html
代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="Test_GridView8.aspx.cs" Inherits="GridView_Test_GridView8" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>无标题页</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="form1" runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:Repeater runat="server" ID="objRepeater">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<HeaderTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
供应商</th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<th width="250px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
供应商2</th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
供应商3</th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
供应商4</th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>s
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</HeaderTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<del>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#Eval("CategoryName") %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</del>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:Repeater DataSource='<%#GetChildren() %>' runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td width="250px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#Eval("ProductName") %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td width="100px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#Eval("UnitPrice","{0:c}") %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td width="100px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<del style="background-color: Red">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#Eval("UnitsInStock","{0:c}") %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</del>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:Repeater>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<AlternatingItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</AlternatingItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<SeparatorTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SeparatorTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<FooterTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</FooterTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:Repeater>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
后代
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Collections;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public partial class GridView_Test_GridView8 : System.Web.UI.Page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
变量#region 变量
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected string strFields = "";//字段
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected string strTable = ""; //表名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected string strWhere = ""; //条件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected string strSql_Categories = " select CategoryName from Categories where CategoryID = 1"; //执行的SQL
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataSet ds = new DataSet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!IsPostBack)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GetData(); //加载显示的数据
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//得到Product表中的数据集
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void GetData()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ds = C_Categories.Instance.GetList_Eds(strSql_Categories);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (ds.Tables[0].Rows.Count > 0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.objRepeater.DataSource = ds.Tables[0];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//objGridView.DataKeyNames = new string[] { "ProductID" };//主键(注意DataKeyNames 是复数间接告诉我们这里是可以有多个字段即可以是联合主键)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.objRepeater.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public DataSet GetChildren()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string strSql_Products = "select * from products where categoryid in (select categoryid from categories where categoryid=1)";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return C_Products.Instance.GetList_Eds(strSql_Products);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中间操作类方法:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//常规获得记录
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public DataSet GetList_Eds(string strSql)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (strSql != "")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return DbHelperSql.ExecuteDataSet(strSql.ToString(), null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return null;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
数据库链接:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<appSettings>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<add key="ConnectionString" value="Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=NORTHWIND;Data Source=WANGYONGJUN" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</appSettings>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<connectionStrings>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<add name="NorthwindConnectionString" connectionString="Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=NORTHWIND;Data Source=WANGYONGJUN" providerName="System.Data.SqlClient" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</connectionStrings>
在CSDN上看到大家问这到这种贴子,晚上回家想了下大概做下了
![](http://p.blog.csdn.net/images/p_blog_csdn_net/cefriend/2.gif)
做得不完全,给大家一种思想吧(用到的嵌套Repeater控件)有些出入,楼主可自已再改动下,
http://topic.csdn.net/u/20080414/22/b54c735c-b2c0-4225-9a25-080d1309b168.html
代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="Test_GridView8.aspx.cs" Inherits="GridView_Test_GridView8" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>无标题页</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="form1" runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:Repeater runat="server" ID="objRepeater">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<HeaderTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
供应商</th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<th width="250px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
供应商2</th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
供应商3</th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
供应商4</th>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>s
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</HeaderTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<del>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#Eval("CategoryName") %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</del>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:Repeater DataSource='<%#GetChildren() %>' runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td width="250px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#Eval("ProductName") %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td width="100px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#Eval("UnitPrice","{0:c}") %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td width="100px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<del style="background-color: Red">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#Eval("UnitsInStock","{0:c}") %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</del>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:Repeater>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<AlternatingItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</AlternatingItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<SeparatorTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SeparatorTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<FooterTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</FooterTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:Repeater>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
后代
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Collections;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public partial class GridView_Test_GridView8 : System.Web.UI.Page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
变量#region 变量
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected string strFields = "";//字段
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected string strTable = ""; //表名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected string strWhere = ""; //条件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected string strSql_Categories = " select CategoryName from Categories where CategoryID = 1"; //执行的SQL
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataSet ds = new DataSet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!IsPostBack)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GetData(); //加载显示的数据
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//得到Product表中的数据集
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void GetData()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ds = C_Categories.Instance.GetList_Eds(strSql_Categories);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (ds.Tables[0].Rows.Count > 0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.objRepeater.DataSource = ds.Tables[0];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//objGridView.DataKeyNames = new string[] { "ProductID" };//主键(注意DataKeyNames 是复数间接告诉我们这里是可以有多个字段即可以是联合主键)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.objRepeater.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public DataSet GetChildren()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string strSql_Products = "select * from products where categoryid in (select categoryid from categories where categoryid=1)";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return C_Products.Instance.GetList_Eds(strSql_Products);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中间操作类方法:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//常规获得记录
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public DataSet GetList_Eds(string strSql)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (strSql != "")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return DbHelperSql.ExecuteDataSet(strSql.ToString(), null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return null;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
数据库链接:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<appSettings>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<add key="ConnectionString" value="Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=NORTHWIND;Data Source=WANGYONGJUN" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</appSettings>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<connectionStrings>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<add name="NorthwindConnectionString" connectionString="Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=NORTHWIND;Data Source=WANGYONGJUN" providerName="System.Data.SqlClient" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</connectionStrings>
相关文章推荐
- Mysql中DATE_SUB 使用方法结合查询一天内,一周内,一月内的信息实例讲解
- asp.net Repeater分页实例(PageDataSource的使用)
- 实例讲解Android应用开发中TabHost的使用要点
- struts2 + ajax + json的结合使用--实例讲解
- 详细的Retrofit 2.0 使用教程(含实例讲解)
- struts2 + ajax + json的结合使用,实例讲解
- PHP 类 的使用[实例讲解]
- 实例讲解Android app开发中ListView的基本使用及优化
- SharedPrefernces使用实例讲解
- 这是一份很详细的 Retrofit 2.0 使用教程(含实例讲解)
- Python的字符串模板(Template)使用操作实例讲解
- Linq过滤符号Where/Skip/TakeWhile/Distinct使用实例讲解
- redis在java中的使用(实例讲解)
- 这是一份很详细的 Retrofit 2.0 使用教程(含实例讲解)
- Java wait() notify()方法使用实例讲解
- 实例讲解Android中的AIDL内部进程通信接口使用
- 实例讲解.NET中资源文件的创建与使用
- android简单实例---------------SD卡(外部)存储的使用与讲解
- 实例讲解映像劫持的使用技巧——通过映像劫持实现Notepad2替换记事本