2009-02-11 47 views
2

我已经完成了下面的设置。当我点击CommandField上的“编辑”链接时,RowEditing事件被触发,但该行不允许我编辑;具体而言,DropDownList不会出现。GridView中的DropDownList在编辑时不可用

我的代码似乎符合我可以找到的所有示例。

我可能错过了一些非常基本的东西,因为我似乎是互联网上唯一有这个问题的人。我迫切需要另一双眼睛。

谢谢。

<asp:GridView ID="grdvMachine1" runat="server" AutoGenerateColumns="False" CellSpacing="2" 
    CssClass="GridViewFormat" GridLines="None" Width="500px" 
    OnRowUpdating="grdvMachine1_RowUpdating" OnRowUpdated="grdvMachine1_RowUpdated" 
    OnRowEditing="grdvMachine1_RowEditing" OnRowDeleting="grdvMachine1_RowDeleting"> 
    <PagerSettings Position="Top" /> 
    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" /> 
    <Columns> 
     <asp:BoundField DataField="Day Of Week" HeaderText="Day Of Week" SortExpression="Day Of Week" /> 
     <asp:TemplateField HeaderText="Package" SortExpression="Package"> 
      <EditItemTemplate> 
       <asp:DropDownList ID="comboPackageNames" 
        runat="server" 
        DataSourceID="PackageNames" 
        DataTextField="PackageName" 
        DataValueField="PackageName" 
        SelectedValue='<%# Bind("Package") %>'> 
       </asp:DropDownList> 
       <asp:ObjectDataSource ID="PackageNames" runat="server" SelectMethod="GetSPPList" 
        TypeName="PCS.WebApp.DefaultSchedules"> 
       </asp:ObjectDataSource> 
      </EditItemTemplate> 
      <ItemTemplate> 
       <asp:Label ID="Label1" runat="server" Text='<%# Eval("Package") %>' /> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:CommandField ShowEditButton="true" ShowDeleteButton="true"/> 
    </Columns> 
    <RowStyle BackColor="#EEEEEE" ForeColor="Black" HorizontalAlign="Center" VerticalAlign="Middle" /> 
    <EmptyDataTemplate> 
     There is no schedule for the selected machine 
    </EmptyDataTemplate> 
    <SelectedRowStyle BackColor="#008A8C" Font-Bold="False" ForeColor="White" /> 
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> 
    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" 
     VerticalAlign="Middle" /> 
    <AlternatingRowStyle BackColor="Gainsboro" /> 
</asp:GridView> 

回答

0

我没有GridView的ObjectDataSource。我在代码隐藏中填充它,但显然你不能这样做,并使用CommandField。

+1

很高兴有提醒选择答案或发布赏金。我忘记了这个问题。 – Dave 2009-03-17 13:23:23

0

您的代码对我来说看起来也不错。这里有几件事情,可以帮助您的故障排除:

  1. 尝试用一些简单的文字替换EditItemTemplate中的DropDownList的和ObjectDataSource,然后看看文本显示,当您单击编辑。
  2. 尝试将GridView挂钩到DataSource对象,并从GridView标记中删除OnRowEditing事件。然后看看GridView是否切换到编辑模式OK。
  3. 尝试移动GridView外部的ObjectDataSource。我不知道它有没有什么区别,但我通常会把它放在外面。

让我们知道这是否会改变你的任何事情。

0

尝试从GridView中删除PackageNames ODS。我不确定,但将它嵌套在GridView中有点奇怪。

+2

再次想到,它可能与您的问题无关...... – andleer 2009-03-15 03:27:30