All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
VS.Net,C#,调用,Active,组件_[Asp.Net教程]
将多次查询的数据填充到同一数据源_.net资料_编程技术
Ajax开发过程中提交获取数据的乱码问题_[AJAX教程]
用shtml来include网页文件(须开启SSI)_[Html教程]
PHP环境下配置在线编辑器FCKeditor_[PHP教程]
为AJAX应用程序构建一个错误提交系统_.net资料_编程技术
C#中EventLog组件应用实例
警告!Ajax技术的安全问题不容忽视_.net资料_编程技术
ASP.NET技术中常见问题详细解答及代码_[Asp.Net教程]
推荐文章:在ASP.NET中创建安全web站点_.net资料_编程技术
Reading number is top 10 pictures
福利是必须的
美丽的桂林风光2
2012 national geographic daily picture7
This is heaven to some path
Born After 90 Beijing sports university campus flower photos2
青春清纯美女大集合3
The real super beauty8
Average female college students1
这才叫绝色美女1
你白吃了多少药
Download software ranking
Proficient in JavaScript
Desire a peach blossom
jBuilder2006
C#COM编程指南
C#编程思想
Boxer's Top ten classic battle4
Boxer's Top ten classic battle8
Call Of Duty2
Popkart Cracked versions Mobile phone games
Sora aoi, the nurse, uniform ,nursing assistant
归海一刀 published in(发表于) 2014/1/30 1:27:02 Edit(编辑)
DataList实现“行转列”代码_[Asp.Net教程]

DataList实现“行转列”代码_[Asp.Net教程]

DataList实现“行转列”代码_[Asp.Net教程]
开发中经常遇到行转列的情况,一般都是在SQL中用 case 来解决这类问题,但有时候我们会需要知道列数并做一些事情。
这时,DataList 就发挥它的作用了。主要应用的就是它的RepeatDirection 属性.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataList.aspx.cs" Inherits="temp_DataList" %>





无标题页



名称:

金额:




’>
’>


’>
’>








using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class temp_DataList : System.Web.UI.Page
{
private DataTable getDateTable()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Name", typeof(String)));
dt.Columns.Add(new DataColumn("Money", typeof(Int32)));
DataRow dr;
dr = dt.NewRow();
dr[0] = "岗位工资";
dr[1] = 100;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "养老";
dr[1] = 200;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "午餐";
dr[1] = 300;
dt.Rows.Add(dr);


return dt;
}

private void DataListBind(DataTable dt)
{
int column = dt != null ? dt.Rows.Count : 0;
column = column > 6 ? 6 : column;//样式的原因,控制最多6个
dl.RepeatColumns = column;
dl.RepeatDirection = RepeatDirection.Horizontal;
dl.DataSource = dt;
dl.DataBind();
}


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["dt"] = getDateTable();
DataListBind(ViewState["dt"] as DataTable);
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
DataTable dt = ViewState["dt"] as DataTable;
if (dt != null)
{
DataRow dr;
dr = dt.NewRow();
dr[0] = txtName.Text.Trim();
int money;
int.TryParse(txtMoney.Text, out money);
dr[1] = money;
dt.Rows.Add(dr);
DataListBind(dt);
}

}
}



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.