没有合适的资源?快使用搜索试试~ 我知道了~
SQL语句经典之作!SQL语句经典之作!SQL语句经典之作!SQL语句经典之作!SQL语句经典之作!SQL语句经典之作!SQL语句经典之作!SQL语句经典之作!SQL语句经典之作!
资源推荐
资源详情
资源评论
一. DropDownList
DropDownList
DropDownList
DropDownList
下拉菜单控制 :
:
:
:
if (!IsPostBack)
{
int year = int .Parse( DateTime .Now.Year.ToString());
for ( int i = 0; i < 5; i++)
{
string strDate = (year + i - 4).ToString();
DropD.Items.Insert(i, new ListItem (strDate,strDate));
}
this .DropD.Text=DropD.Items[4].Value;
}
private void Page_Load(object sender, System.EventArgs e)
{
DateTime tnow=DateTime.Now;// 现在时间
ArrayList AlYear=new ArrayList();
int i;
for(i=2002;i<=2010;i++)
AlYear.Add(i);
ArrayList AlMonth=new ArrayList();
for(i=1;i<=12;i++)
AlMonth.Add(i);
if(!this.IsPostBack )
{
DropDownList1.DataSource=AlYear;
DropDownList1.DataBind();// 绑定年
// 选择当前年
DropDownList1.SelectedValue=tnow.Year.ToString();
DropDownList2.DataSource=AlMonth;
DropDownList2.DataBind();// 绑定月
// 选择当前月
DropDownList2.SelectedValue=tnow.Month.ToString();
int year,month;
year=Int32.Parse(DropDownList1.SelectedValue);
month=Int32.Parse(DropDownList2.SelectedValue);
BindDays(year,month);// 绑定天
// 选择当前日期
DropDownList3.SelectedValue=tnow.Day.ToString();
}
}
// 判断闰年
private bool CheckLeap(int year)
{
if((year%4==0)&&(year%100!=0)||(year%400==0))
return true;
else return false;
}
// 绑定每月的天数
private void BindDays( int year,int month)
{ int i;
ArrayList AlDay=new ArrayList();
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
for(i=1;i<=31;i++)
AlDay.Add(i);
break;
case 2:
if (CheckLeap(year))
{for(i=1;i<=29;i++)
AlDay.Add(i);}
else
{for(i=1;i<=28;i++)
AlDay.Add(i);}
break;
case 4:
case 6:
case 9:
case 11:
for(i=1;i<=30;i++)
AlDay.Add(i);
break;
}
DropDownList3.DataSource=AlDay;
DropDownList3.DataBind();
}
// 选择年
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e )
{
int year,month;
year=Int32.Parse(DropDownList1.SelectedValue);
month=Int32.Parse(DropDownList2.SelectedValue);
BindDays(year,month);
}
// 选择月
private void DropDownList2_SelectedIndexChanged(object sender ,
System.EventArgs e)
{
int year,month;
year=Int32.Parse(DropDownList1.SelectedValue);
month=Int32.Parse(DropDownList2.SelectedValue);
BindDays(year ,month);
}
二. GridView
GridView
GridView
GridView
添加统计 (
(
(
(
合计 )
)
)
)
行
前提:设置属性 ShowFooter="True" 方法一:使用 SQL 查询统计出合计值,在绑定 GridView 时让
其结果赋于一个 DataTable( 全局变量 ) ,然后在 RowDataBound 事件中
程序代码 :
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = " 合计 ";
e.Row.Cells[3].Text = dtSum.Rows[0][0].ToString();
e.Row.Cells[4].Text = dtSum.Rows[0][1].ToString();
e.Row.Cells[5].Text = dtSum.Rows[0][2].ToString();
e.Row.Cells[6].Text = dtSum.Rows[0][3].ToString();
e.Row.Cells[7].Text = dtSum.Rows[0][4].ToString();
e.Row.Cells[8].Text = dtSum.Rows[0][5].ToString();
e.Row.Cells[9].Text = dtSum.Rows[0][6].ToString();
e.Row.Cells[10].Text = dtSum.Rows[0][7].ToString();
e.Row.Cells[11].Text = dtSum.Rows[0][8].ToString();
}
其中 dtSum 是那个全局 DataTable ,在绑定 GridView 同时将 SQL 查询的结果赋给它;效果如下:
方法二、直接把对应列每一行的值相加 ( 不做数据查询,在 RowDataBound 事件中运算 )
int mysum1 = 0;
int mysum2 = 0;
protected void GridList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
DataRowView myrows=(DataRowView)e.Row.DataItem;
mysum1 +=Convert .ToInt32 (myrows[2].ToString ());
mysum2 += Convert.ToInt32(myrows[3].ToString());
}
// 合计
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = " 合计 ";
e.Row.Cells[1].Text = mysum1.ToString();
e.Row.Cells[2].Text = mysum2.ToString();
}
}
protected void GridView1_RowCreated( object sender, GridViewRowEventArgs
e)
{
switch (e.Row.RowType)
{
case DataControlRowType .Header:
// 第一行表头
//for (int i = 0; i < GridView1.Columns.Count - 1; i++)
//{
TableCellCollection tcHeader = e.Row.Cells;
tcHeader.Clear();
tcHeader.Add( new TableHeaderCell ());
tcHeader[0].Attributes.Add( "rowspan" , "2" ); // 跨 Row
tcHeader[0].Attributes.Add( "bgcolor" , "white" );
tcHeader[0].Text = " 时间 " ;
//select d
//
int i = 0;
int j = 0;
//int Index =DropDownList1.Items.Add(1);
for ( i = 1; i <3; i++)
{
tcHeader.Add( new TableHeaderCell ());
tcHeader[i].Attributes.Add( "colspan" , "2" ); // 跨
Column
tcHeader[i].Text = "" + DropDownList1.Items[i-
1].Value + "</tr>" ;
//if (i == 18)
//{
// tcHeader.Add(new TableHeaderCell());
// tcHeader[i].Attributes.Add("colspan", "2");
// 跨 Column
// tcHeader[i].Text = " 交易所 <tr>";
//}
//if (i == 19)
//{
// tcHeader.Add(new TableHeaderCell());
// tcHeader[i].Attributes.Add("colspan", "2");
// 跨 Column
// tcHeader[i].Text = " 合计 <tr>";
//}
}
//tcHeader.Add(new TableHeaderCell());
//tcHeader[i + 1].Attributes.Add("colspan", "2"); // 跨
Column
//tcHeader[i + 1].Text = " 合计 <tr>";
for (j = i; j <10; j++)
{
tcHeader.Add( new TableHeaderCell ());
tcHeader[j].Text = " 毛重 " ;
tcHeader.Add( new TableHeaderCell ());
tcHeader[j].Text = " 净重 " ;
}
// tcHeader.Add(new TableHeaderCell());
// tcHeader[1].Attributes.Add("colspan", "2"); // 跨
Column
剩余62页未读,继续阅读
资源评论
我是一只小小小的菜鸟
- 粉丝: 11
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功