我有一个绑定到对象数据源的表单视图。objectdatasource 从列表集合中获取其值。为了实现级联下拉列表,我不得不为下拉列表切换几个文本框控件。这些值填充得很好,级联下拉列表效果很好,但是在插入时我收到了这个烦人的无用消息
“指数数组的边界之外。” 所以我一直试图弄清楚这一点并且不能。
假设是我的下拉列表导致了问题,我尝试将此代码添加到后面的代码中,因为我手动绑定它们,因此它们没有 Text='<%# Bind("GroupID") %>
protected void formGroupInput_ItemInserting(object sender, FormViewInsertEventArgs e)
{
if (formGroupInput.CurrentMode == FormViewMode.Insert)
{
e.Values["ddlStartTime"] = ((DropDownList)((FormView)sender).FindControl("ddlStartTime")).SelectedItem;
e.Values["ddlEndTime"] = ((DropDownList)((FormView)sender).FindControl("ddlEndTime")).SelectedItem;
e.Values["ddlRoomName"] = ((DropDownList)((FormView)sender).FindControl("ddlRoomName")).SelectedItem;
e.Values["ddlJackNumber"] = ((DropDownList)((FormView)sender).FindControl("ddlJackNumber")).SelectedItem;
e.Values["ddlInternetType"] = ((DropDownList)((FormView)sender).FindControl("ddlInternetType")).SelectedItem;
}
}
我猜它与此有关,因为当我尝试通过在我的 DLL 中的输入法上放置一个断点来调试它时,它甚至在显示错误之前还没有达到它。
谢谢
填充下拉列表的代码
protected void formGroupInput_DataBound(object sender, EventArgs e)
{
if (formGroupInput.CurrentMode == FormViewMode.Insert)
{
DropDownList roomName = (DropDownList)(formGroupInput.Row.FindControl("ddlRoomName"));
roomName.DataSource = getrooms.FetchRooms();
roomName.DataTextField = "RoomName";
roomName.DataValueField = "intRoom";
roomName.DataBind();
****Same concept for other 2 dropdownlist ******
}
}
页面加载我称之为
protected void Page_Load(object sender, EventArgs e)
{
DropDownList startTime = (DropDownList)(formGroupInput.Row.FindControl("ddlStartTime"));
if (startTime.Items.Count == 0)
{
startTime.Items.Add("12:00AM");
startTime.Items.Add("12:30AM");
for (int i = 1; i <= 11; i++)
{
startTime.Items.Add(i + ":00AM");
startTime.Items.Add(i + ":15AM");
startTime.Items.Add(i + ":30AM");
}
startTime.Items.Add("12:00PM");
startTime.Items.Add("12:30PM");
for (int i = 1; i <= 11; i++)
{
startTime.Items.Add(i + ":00PM");
startTime.Items.Add(i + ":15PM");
startTime.Items.Add(i + ":30PM");
}
}
DropDownList endTime = (DropDownList)(formGroupInput.Row.FindControl("ddlEndTime"));
if (endTime.Items.Count == 0)
{
Same As Above
}