0
我有一個formview綁定到一個objectdatasource。 objectdatasource從列表集合中獲取其值。爲了實現級聯下拉列表,我不得不爲下拉列表切換少數文本框控件。值填充罰款級聯下拉菜單很好,但插入我得到這惱人的無益的消息Asp.net Formview使用C#
「索引超出了數組的界限。所以我一直在試圖弄清楚和不能。
假設它是我的下拉列表引起的問題我試圖將此代碼添加到後面的代碼,因爲我手動綁定它們,所以它們沒有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
}
你知道拋出異常的方法嗎?你可以發佈堆棧跟蹤嗎? – 2013-03-12 19:28:07
另外,請發佈您用於填充下拉列表的代碼。 – 2013-03-12 19:29:38
您是否嘗試在頂部放置斷點並逐步遍歷每個formGroupInput_ItemInsert *函數? – tgolisch 2013-03-12 19:58:44