我正试图在另一个GridView中的GridView中编辑值。我能够在第一个GridView上编辑值,但是当我在子GridView上点击“编辑”时,除了回发之外没有任何反应。
我的GridView结构如下:
<asp:GridView ID="gwProperties" runat="server" Width="100%"
onrowediting="gwProperties_RowEditing" AutoGenerateColumns="False"
DataKeyNames="Name,IsActive"
onrowcancelingedit="gwProperties_RowCancelingEdit"
onrowdeleting="gwProperties_RowDeleting"
ShowFooter="True" onrowupdating="gwProperties_RowUpdating">
<FooterStyle BackColor="#20334F" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="green" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField ShowEditButton="true" EditText="Ret" UpdateText="Gem" CancelText="Annuller" />
<asp:BoundField DataField="Name" HeaderText="Navn" SortExpression="Name" />
<asp:TemplateField HeaderText="Aktiv" SortExpression="IsActive" Visible="true">
<ItemTemplate>
<asp:Label runat="server" ID="Label2" Text='<%# (Boolean.Parse(Eval("IsActive").ToString())) ? "Aktiv" : "Inaktiv" %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox runat="server" ID="cbIsPropertyActive" Checked='<%# Bind("IsActive") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
</td>
</tr>
<tr>
<td colspan="100%">
<asp:GridView DataKeyNames="StreetName,Zip,City,Country" runat="server" ID="gwAddresses" Width="100%" AutoGenerateColumns="false" DataSource='<%#Eval("Addresses") %>' OnRowEditing="gwAddresses_RowEditing">
<Columns>
<asp:TemplateField HeaderText="Vejnavn">
<ItemTemplate>
<asp:Label runat="server" ID="lblStreetName" Text='<%# Bind("StreetName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtStreetName" Text='<%# Bind("StreetName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" EditText="Ret" UpdateText="Gem" CancelText="Annuller" />
<asp:BoundField DataField="Zip" HeaderText="Postnummer" SortExpression="Zip" />
<asp:BoundField DataField="City" HeaderText="By" SortExpression="City" />
<asp:BoundField DataField="Country" HeaderText="Land" SortExpression="Country" />
<asp:TemplateField>
<ItemTemplate>
</td>
</tr>
<tr>
<td colspan="100%">
<asp:GridView runat="server" ID="gwStreetNumbers" Width="100%" AutoGenerateColumns="false" DataSource='<%#Eval("StreetNumbers") %>' OnRowEditing="gwAddresses_RowEditing">
<Columns>
<asp:BoundField DataField="Number" HeaderText="Nummer" SortExpression="Number" />
<asp:BoundField DataField="Letter" HeaderText="Bogstav" SortExpression="Letter" />
<asp:TemplateField>
<ItemTemplate>
</td>
</tr>
<tr>
<td colspan="100%">
<asp:GridView runat="server" ID="gwPrivateLeases" Width="100%" AutoGenerateColumns="false" DataSource='<%#Eval("LeaseTypes.PrivateLeases") %>' OnRowEditing="gwAddresses_RowEditing">
<Columns>
<asp:TemplateField HeaderText="Aktiv">
<ItemTemplate>
<asp:Label runat="server" ID="lblIsLeaseActive" Text='<%# (Boolean.Parse(Eval("IsActive").ToString())) ? "Aktiv" : "Inaktiv" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TakeoverDate" HeaderText="Overtagelsesdato" SortExpression="TakeoverDate" />
<asp:BoundField DataField="Floor" HeaderText="Sal" SortExpression="Floor" />
<asp:BoundField DataField="Side" HeaderText="Side" SortExpression="Side" />
<asp:BoundField DataField="Regulating" HeaderText="Regulering" />
<asp:HyperLinkField DataNavigateUrlFields="Prospect" HeaderText="Prospekt" />
<asp:HyperLinkField DataNavigateUrlFields="FloorPlanDrawing" HeaderText="Plantegning" />
<asp:BoundField DataField="LeasingPeriod" HeaderText="Lejeperiode" />
<asp:BoundField DataField="SquareMetre" HeaderText="Kvadratmeter" />
<asp:BoundField DataField="Rent" HeaderText="Husleje" />
<asp:BoundField DataField="NumberOfRooms" HeaderText="Antal værelser" />
<asp:BoundField DataField="ACConsumption" HeaderText="A/C forbrug" />
<asp:BoundField DataField="PaymentInAdvance" HeaderText="Forudbetalt leje" />
<asp:BoundField DataField="Termination" HeaderText="Opsigelse (antal måneder)" />
<asp:TemplateField HeaderText="Møbleret">
<ItemTemplate>
<asp:Label runat="server" ID="lblIsFurnished" Text='<%# (Boolean.Parse(Eval("IsFurnished").ToString())) ? "Ja" : "Nej" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Husdyr">
<ItemTemplate>
<asp:Label runat="server" ID="lblIsFurnished" Text='<%# (Boolean.Parse(Eval("IsAnimalsAllowed").ToString())) ? "Ja" : "Nej" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Altan">
<ItemTemplate>
<asp:Label runat="server" ID="lblIsFurnished" Text='<%# (Boolean.Parse(Eval("HasBalcony").ToString())) ? "Ja" : "Nej" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delevenlig">
<ItemTemplate>
<asp:Label runat="server" ID="lblIsFurnished" Text='<%# (Boolean.Parse(Eval("CanBeShared").ToString())) ? "Ja" : "Nej" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TypeOfRental" HeaderText="Lejemålstype" />
</Columns>
</asp:GridView>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
</td>
</tr>
<tr>
<td colspan="100%">
<asp:GridView runat="server" ID="gwBusinessLeases" Width="100%" AutoGenerateColumns="false" DataSource='<%#Eval("LeaseTypes.BusinessLeases") %>' OnRowEditing="gwAddresses_RowEditing">
<Columns>
<asp:TemplateField HeaderText="Aktiv">
<ItemTemplate>
<asp:Label runat="server" ID="lblIsLeaseActive" Text='<%# (Boolean.Parse(Eval("IsActive").ToString())) ? "Aktiv" : "Inaktiv" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TakeoverDate" HeaderText="Overtagelsesdato" SortExpression="TakeoverDate" />
<asp:BoundField DataField="Floor" HeaderText="Sal" SortExpression="Floor" />
<asp:BoundField DataField="Side" HeaderText="Side" SortExpression="Side" />
<asp:BoundField DataField="Regulating" HeaderText="Regulering" />
<asp:HyperLinkField DataNavigateUrlFields="Prospect" HeaderText="Prospekt" />
<asp:HyperLinkField DataNavigateUrlFields="FloorPlanDrawing" HeaderText="Plantegning" />
<asp:BoundField DataField="MinimumSquareMetre" HeaderText="Kvadratmeter min." />
<asp:BoundField DataField="MaximumSquareMetre" HeaderText="Kvadratmeter max." />
<asp:BoundField DataField="YearlyRentPerSquareMetre" HeaderText="Årlig leje pr. m2" />
<asp:BoundField DataField="ACYearlyOperationalCostPerSquareMetre" HeaderText="Årlig drift pr. m2" />
<asp:BoundField DataField="Deposit" HeaderText="Depositum" />
<asp:BoundField DataField="MonthsOfPaymentInAdvance" HeaderText="Forudbetalt leje (antal måneder)" />
<asp:BoundField DataField="VATAgreements" HeaderText="Moms" />
<asp:BoundField DataField="MonthsOfTermOfNotice" HeaderText="Opsigelsesvarsel" />
<asp:BoundField DataField="TypeOfRental" HeaderText="Lejemålstype" />
</Columns>
</asp:GridView>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
对不起文字的墙 - 它非常庞大;-)实际上它是四个嵌套的网格视图,但我想当我能够编辑第一个嵌套时,我可以对其他子网格视图执行完全相同的操作。< / p>
我在.cs文件中尝试过类似的内容:
protected void gwAddresses_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView gwAddresses = (GridView)sender;
gwAddresses.EditIndex = e.NewEditIndex;
FillGridView();
}
但它什么都没做。这有可能吗?我找到了一些关于此的优秀文章,但我根本无法让它起作用: - /
我有一种奇怪的感觉,我正在使用错误的控件。
我的对象结构如下:
- Property
- List<Address>
- Address object: List<StreetNumber>
- StreetNumber object: List<LeaseTypes>
- LeseTypes object: List<PrivateLease> and List<BusinessLease>
所以基本上它是一个五步深度结构,我需要在我的ASP.NET解决方案中绑定并在前端进行编辑。
这给了我一个严重的头痛,所以如果有人对如何实现这一目标有一点点暗示,我会非常高兴!
提前致谢!