2012-01-27 100 views
1

我有一個asp:gridview,我試圖用obout:combobox替換asp:dropdownlist。我在網格外部的頁面上使用組合框,並按預期工作。在GridView的代碼看起來像這樣數據網格中的obout組合框

<asp:GridView ID="dgKSA" runat="server" AutoGenerateColumns="False" GridLines="none" 
    Width="980px" Style="border: 1px solid #404040" CellPadding="5" AlternatingRowStyle-BackColor="#F0F3F4" 
    ShowHeader="false"> 
    <Columns> 
     <asp:TemplateField ItemStyle-VerticalAlign="top"> 
      <ItemTemplate> 
       <obout:ComboBox ID="ddlImportanceInDg" runat="server" Visible="true" Enabled="true" > 
        <obout:ComboBoxItem ID="ComboBoxItem1" runat="server" Value="5" Text="Extremely Important" /> 
        <obout:ComboBoxItem ID="ComboBoxItem2" runat="server" Value="4" Text="Important" /> 
        <obout:ComboBoxItem ID="ComboBoxItem3" runat="server" Value="3" Text="Moderately Important" /> 
        <obout:ComboBoxItem ID="ComboBoxItem4" runat="server" Value="2" Text="Unimportant" /> 
        <obout:ComboBoxItem ID="ComboBoxItem5" runat="server" Value="1" Text="Extremely Unimportant" /> 
        <obout:ComboBoxItem ID="ComboBoxItem6" runat="server" Value="99" Text="Not Applicable" 
         Selected="true" /> 
       </obout:ComboBox> 
       <%--<asp:DropDownList runat="server" ID="ddlImportanceInDg"> 
        <asp:ListItem Value="5">Extremely Important</asp:ListItem> 
        <asp:ListItem Value="4">Important</asp:ListItem> 
        <asp:ListItem Value="3">Moderately Important</asp:ListItem> 
        <asp:ListItem Value="2">Unimportant</asp:ListItem> 
        <asp:ListItem Value="1">Extremely Unimportant</asp:ListItem> 
        <asp:ListItem Value="99" Selected="true">Not Applicable</asp:ListItem> 
       </asp:DropDownList>--%> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

就是這樣......在頁面繪製時,組合框顯示出來,但只有最後COMBOX中有任何項目。

希望有人有一個想法。 謝謝 shannon

回答

1

我意識到你問了這個7個月前,但我有同樣的問題,並找到了解決方案,所以我想我會分享它。

基本上,您必須在創建行時爲ComboBox分配唯一的ID。

Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) 
     If e.Row.RowType = DataControlRowType.DataRow Then 
      Dim ComboBox1 As Obout.ComboBox.ComboBox = CType(e.Row.FindControl("ComboBox1"), Obout.ComboBox.ComboBox) 

      ComboBox1.ID = "ComboBox1_" & e.Row.RowIndex 
     End If 
End Sub 
相關問題