编辑时 GridView 中的 DropDownList 不可用

发布于 2024-07-13 08:28:41 字数 2431 浏览 8 评论 0原文

我有下面的设置。 当我单击 CommandField 上的“编辑”链接时,会触发 RowEditing 事件,但该行不允许我进行编辑; 具体来说,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>

I've got the setup below. When I click the 'Edit' link on the CommandField, a RowEditing event gets fired, but the row does not allow me to edit; specifically, the DropDownList does not appear.

My code seems to conform to all the examples I can find.

I'm probably missing something very basic, as I seem to be the only person on the internet having this problem. I'm desperate for another pair of eyes.

Thanks.

    <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

入怼 2024-07-20 08:28:42

你的代码对我来说看起来也不错。 以下几点可能有助于您进行故障排除:

  1. 尝试用一些简单的文本替换 EditItemTemplate 的 DropDownList 和 ObjectDataSource,然后查看单击“编辑”时是否显示该文本。
  2. 尝试将 GridView 连接到 DataSource 对象,并从 GridView 标记中删除 OnRowEditing 事件。 然后看看GridView是否切换到编辑模式就OK了。
  3. 尝试将 ObjectDataSource 移到 GridView 之外。 我不知道这是否有什么区别,但我通常把我的放在外面。

如果这对您有任何改变,请告诉我们。

Your code looks OK to me, too. Here are a couple of things that might help your troubleshooting:

  1. Try replacing the EditItemTemplate's DropDownList and ObjectDataSource with some simple text, then see if the text shows up when you click Edit.
  2. Try hooking the GridView up to a DataSource object, and remove the OnRowEditing event from the GridView tag. Then see if the GridView switches to Edit mode OK.
  3. Try moving the ObjectDataSource outside of the GridView. I don't know if it makes any difference, but I usually have mine located outside.

Let us know if this changes anything for you.

-残月青衣踏尘吟 2024-07-20 08:28:42

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

Try removing your PackageNames ODS from within your GridView. I don't know for sure, but it is a little odd to have it nested within the GridView.

肩上的翅膀 2024-07-20 08:28:42

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

I didn't have an ObjectDataSource for the GridView. I was populating it in the code-behind, but apparently you can't do that and use a CommandField.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文