你好,你可以在Page_Load事件中加载第一个ComboBox的数据,在FpSpread1_UpdateCommand事件中得到第一个ComboBox选择的值并加载第二个ComboBox的值
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
return;
DataTable dt1 = new DataTable();
dt1.Columns.AddRange(
new DataColumn[] {
new DataColumn("ID", typeof(string)),
new DataColumn("Name", typeof(string))});
dt1.Rows.Add(new object[] { 1, "Item1" });
dt1.Rows.Add(new object[] { 2, "Item2" });
dt1.Rows.Add(new object[] { 3, "Item3" });
FarPoint.Web.Spread.ComboBoxCellType cmbbx = new FarPoint.Web.Spread.ComboBoxCellType();
cmbbx.ShowButton = true;
cmbbx.AutoPostBack = true;
cmbbx.DataSource = dt1;
cmbbx.DataTextField = "Name";
cmbbx.DataValueField = "ID";
cmbbx.UseValue = true;
FpSpread1.ActiveSheetView.Columns[0].CellType = cmbbx;
}
protected void FpSpread1_UpdateCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
if (e.SheetView.ActiveColumn == 0 && e.CommandArgument.ToString().Equals(FpSpread1.Sheets[0].ActiveRow.ToString()))
{
DataTable dt2 = new DataTable();
dt2.Columns.AddRange(
new DataColumn[] {
new DataColumn("MstID", typeof(string)),
new DataColumn("ID", typeof(string)),
new DataColumn("Name", typeof(string))});
dt2.Rows.Add(new object[] { 1, 1, "A" });
dt2.Rows.Add(new object[] { 1, 2, "B" });
dt2.Rows.Add(new object[] { 1, 3, "C" });
dt2.Rows.Add(new object[] { 2, 1, "D" });
dt2.Rows.Add(new object[] { 2, 2, "E" });
dt2.Rows.Add(new object[] { 2, 3, "F" });
dt2.Rows.Add(new object[] { 3, 1, "G" });
dt2.Rows.Add(new object[] { 3, 2, "H" });
dt2.Rows.Add(new object[] { 3, 3, "I" });
FarPoint.Web.Spread.ComboBoxCellType cmbbx = new FarPoint.Web.Spread.ComboBoxCellType();
List<String> list = new List<string>();
foreach (DataRow row in dt2.Select(String.Format("MstID = {0}",e.EditValues[0].ToString())))
{
list.Add(row["Name"].ToString());
}
cmbbx.ShowButton = true;
cmbbx.AutoPostBack = true;
cmbbx.DataSource = list;
FpSpread1.Sheets[0].Cells[e.SheetView.ActiveRow, 1].CellType = cmbbx;
}
} |