前台页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="gzrw_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>测试</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<br />
<telerik:RadComboBox ID="ddlStyle" Skin="Windows7" runat="server" Filter="Contains" Culture="zh-CN" AutoPostBack="true" OnSelectedIndexChanged="ddlStyle_SelectedIndexChanged">
<Items>
<telerik:RadComboBoxItem runat="server" Text="请选择周期类型" Value="" />
<telerik:RadComboBoxItem runat="server" Text="周" Value="周" />
<telerik:RadComboBoxItem runat="server" Text="月" Value="月" />
</Items>
</telerik:RadComboBox>
<telerik:RadComboBox ID="ddlShow" Skin="Windows7" runat="server" Filter="Contains" Culture="zh-CN">
</telerik:RadComboBox>
<br />
<asp:TextBox ID="my" runat="server" Text="fa"></asp:TextBox>
</div>
</form>
</body>
</html>
后台页面:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
public partial class gzrw_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//String SData = "1 1,2 2,3 3,4 4,5 5,6 6,7 7,8 8,9 9,10 10,11 11,12 12,13 13,14 14,15 15,16 16,17 17,18 18,19 19,20 20,21 21,22 22,23 23,24 24,25 25,26 26,27 27,28 28,29 29,30 30,31 31";
//String[] x = StringSplit(SData, ",");
//String[,] y = new String[x.Length, 2];
/初始化y
//String[] temp = null;
//for (int i = 0; i < x.Length; i++)
//{
// temp = StringSplit(x[i], " ");
// for (int j = 0; j < 2; j++)
// {
// y[i, j] = temp[j];
// }
//}
//DataTable dt = Convert(new String[] { "value", "text" }, y);
//ddlShow.DataValueField = "value";
//ddlShow.DataTextField = "text";
//ddlShow.DataSource = dt.DefaultView;
//ddlShow.DataBind();
}
}
protected void ddlStyle_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
ddlShow.Text = "";
LoadddlShow(e.Value);
my.Text = e.Value;
}
protected void LoadddlShow(string continentID)
{
String SData = String.Empty;
if (continentID == "月")
{
SData = "1 1,2 2,3 3,4 4,5 5,6 6,7 7,8 8,9 9,10 10,11 11,12 12,13 13,14 14,15 15,16 16,17 17,18 18,19 19,20 20,21 21,22 22,23 23,24 24,25 25,26 26,27 27,28 28,29 29,30 30,31 31";
}
else if (continentID == "周")
{
SData = "一 一,二 二,三 三,四 四,五 五,六 六,七 七";
}
else
{
return;
}
String[] x = StringSplit(SData, ",");
String[,] y = new String[x.Length, 2];
///初始化y
String[] temp = null;
for (int i = 0; i < x.Length; i++)
{
temp = StringSplit(x[i], " ");
for (int j = 0; j < 2; j++)
{
y[i, j] = temp[j];
}
}
DataTable dt = Convert(new String[] { "value", "text" }, y);
ddlShow.DataValueField = "value";
ddlShow.DataTextField = "text";
ddlShow.DataSource = dt.DefaultView;
ddlShow.DataBind();
}
/// <summary>
/// 分割字符串为数组
/// </summary>
/// <param name="strSource"></param>
/// <param name="strSplit"></param>
/// <returns></returns>
public string[] StringSplit(string strSource, string strSplit)
{
string[] strtmp = new string[1];
int index = strSource.IndexOf(strSplit, 0);
if (index < 0)
{
strtmp[0] = strSource;
return strtmp;
}
else
{
strtmp[0] = strSource.Substring(0, index);
return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);
}
}
/// <summary>
/// 采用递归将字符串分割成数组
/// </summary>
/// <param name="strSource"></param>
/// <param name="strSplit"></param>
/// <param name="attachArray"></param>
/// <returns></returns>
private string[] StringSplit(string strSource, string strSplit, string[] attachArray)
{
string[] strtmp = new string[attachArray.Length + 1];
attachArray.CopyTo(strtmp, 0);
int index = strSource.IndexOf(strSplit, 0);
if (index < 0)
{
strtmp[attachArray.Length] = strSource;
return strtmp;
}
else
{
strtmp[attachArray.Length] = strSource.Substring(0, index);
return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);
}
}
/// <summary>
/// 反一个M行N列的二维数组转换为DataTable
/// </summary>
/// <param name="ColumnNames">一维数组,代表列名,不能有重复值</param>
/// <param name="Arrays">M行N列的二维数组</param>
/// <returns>返回DataTable</returns>
/// <remarks>Y法</remarks>
public static DataTable Convert(string[] ColumnNames, string[,] Arrays)
{
DataTable dt = new DataTable();
foreach (string ColumnName in ColumnNames)
{
dt.Columns.Add(ColumnName, typeof(string));
}
for (int i1 = 0; i1 < Arrays.GetLength(0); i1++)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < ColumnNames.Length; i++)
{
dr[i] = Arrays[i1, i].ToString();
}
dt.Rows.Add(dr);
}
return dt;
}
}