编辑时 GridView 中的 DropDownList 不可用
我有下面的设置。 当我单击 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的代码对我来说看起来也不错。 以下几点可能有助于您进行故障排除:
如果这对您有任何改变,请告诉我们。
Your code looks OK to me, too. Here are a couple of things that might help your troubleshooting:
Let us know if this changes anything for you.
尝试从 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.
我没有 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.