我在一個Tab Panel中有一系列的GridViews - 數據綁定到一個通用的Business Objects列表。使用下拉列表編輯Gridview行太寬 - 我怎樣才能使用彈出式面板呢?
GridView中列所有類似以下內容:
<asp:TemplateField HeaderText="Company" SortExpression="Company.ShortName">
<ItemTemplate>
<asp:Label ID="lblCompany" runat="server" Text='<%# Bind("Company.ShortName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlCompany" runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
GridView控件在行的開始產生「編輯」鏈接,所有的事件觸發確定。問題是數據越來越長。在「顯示模式」下,這很好,因爲GridView控件足夠聰明,可以將一些文本分成多行(特別是Project,Title和Worker名稱可以變得很長)。
問題進入編輯模式。下拉列表不要將條目分成多行(出於顯而易見的原因)。在Gridview的一行中進入Edit ode可以使Griview水平擴展爲屏幕尺寸的兩倍(通過Master頁面和CSS的寬度限制,但這只是一個相關的問題)。
我需要的是像ModalPopup - 但嘗試將它綁定到EditItemTemplate中的ID會在頁面呈現時給我提供錯誤(因爲'ddlXXXX'在當時不存在)。此外,我不知道如何動態填充面板,以便我可以從中獲得響應(如他們選擇的公司的ID)。
我也試圖避免JavaScript,並希望這是一個'純粹的'aspx /代碼隱藏解決方案(爲了簡單起見等)。
我發現的所有例子都是預定義面板的Modal Popups。即使它(彈出式面板)類似於複選框列表,它也可能是數據綁定到我已準備好的SortedList以及確定/取消按鈕組合來接受或忽略事情。我只是不確定在哪裏。
我願意接受建議。提前致謝。
編輯:最終的解決方案如下所示:
<asp:TemplateField HeaderText="Company" SortExpression="Company.ShortName">
<ItemTemplate>
<asp:Label ID="lblCompany" runat="server" Text='<%# Bind("Company.ShortName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkCompany" runat="server" Text='<%# Bind("Company.ShortName") %>'></asp:LinkButton>
<asp:Panel ID="pnlCompany" runat="server" style="display:none">
<div>
<asp:DropDownList ID="ddlCompany" runat="server" ></asp:DropDownList>
<br/>
<asp:ImageButton ID="btnOKCo" runat="server" ImageUrl="~/Images/greencheck.gif" OnCommand="PopupButton_Command" CommandName="SelectCO" />
<asp:ImageButton ID="btnCxlCo" runat="server" ImageUrl="~/Images/RedX.gif" />
</div>
</asp:Panel>
<cc1:ModalPopupExtender ID="mpeCompany" runat="server"
TargetControlID="lnkCompany" PopupControlID="pnlCompany"
BackgroundCssClass="modalBackground" CancelControlID="btnCxlCo"
DropShadow="true" PopupDragHandleControlID="pnlCompany" />
</EditItemTemplate>
</asp:TemplateField>
而在代碼隱藏,lstIDLabor是數據線的泛型列表(其中公司是屬性之一,這也是一個業務對象)即綁定到GridView:
Sub PopupButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim intRow As Integer
Dim intVal As Integer
RestoreFromSessionVariables()
Select Case e.CommandName
Case "SelectCO"
intRow = grdIDCostLabor.EditIndex
Dim ddlCo As DropDownList = CType(grdIDCost.Rows(intRow).FindControl("ddlCompany"), DropDownList)
intVal = ddlCo.SelectedValue
lstIDLabor(intRow).CompanyID = intVal
lstIDLabor(intRow).Company = Company.Read(intVal)
Case Else
'
End Select
MakeSessionVariables()
BindGrids()
End Sub
彈出作品下拉彈出(剛需在風格上工作)。一個問題 - 我在哪裏捕獲「OkButton.Select」事件?由於它位於EditItemTemplate中,因此代碼隱藏不知道該按鈕是否存在。我需要能夠抓取下拉列表中的值並重新綁定數據,以便新的文本顯示在LinkButton中。 – David 2010-04-19 11:32:33
您應該可以將EditTemplate中的ddl綁定到公司ID。回顧我剛剛編輯的答案。關於選擇,我不認爲你需要它。 你使用什麼樣的數據源? – alejandrobog 2010-04-19 14:08:09
我正在使用自定義業務對象的通用列表。我向OK圖像按鈕添加了以下內容:OnCommand =「PopupButton_Command」CommandName =「SelectCO」,當它點擊它時,它現在正在那裏。我只需要弄清楚如何將新值插入到列表中,以便LinkButton在彈出消失時反映新值(然後在Gridview.RowUpdating事件最終觸發時返回Label) – David 2010-04-19 14:42:47