我搜索了这个问题,但反过来,ddl更新了gridview而不是我要寻找的东西。 我有一个非常简单的gridview:
<asp:GridView DataKeyNames="id" ID="grdCantieri" runat="server" AutoGenerateColumns="False" AllowPaging="True" CellPadding="4" DataSourceID="sqlDSCantieri" ForeColor="#333333" GridLines="None" AllowSorting="True" BorderColor="#E1E1E1" BorderStyle="Solid" BorderWidth="3px" CssClass="gridview" PageSize="100">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" Visible="false" />
<asp:BoundField DataField="Descr" HeaderText="Cantiere" SortExpression="Descr" />
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="lnkAggiornaCant" runat="server" CausesValidation="True"
CommandName="Update" Text="Aggiorna" ForeColor="White"></asp:LinkButton>
<asp:LinkButton ID="lnkAnnullaCant" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Annulla" ForeColor="White"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkModificaCant" runat="server" CausesValidation="False"
CommandName="Edit" Text="Modifica" ShowEditButton="True" ></asp:LinkButton>
<asp:LinkButton ID="lnkEliminaCant" runat="server" CausesValidation="False"
CommandName="Delete" Text="Elimina" OnClientClick="return confirm('Questo cantiere verrà eliminato, confermi?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="sqlDSCantieri" runat="server" ConnectionString="<%$ ConnectionStrings:dbVirtualTimbConnectionString %>" SelectCommand="SELECT [Descr], [id] FROM [Cantieri] WHERE ([rfCliente] = @rfCliente) ORDER BY [Descr]" DeleteCommand="DELETE FROM [Cantieri] WHERE [id] = @id" InsertCommand="INSERT INTO [Cantieri] ([Descr], [id]) VALUES (@Descr, @id)" UpdateCommand="UPDATE [Cantieri] SET [Descr] = @Descr WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Descr" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter DefaultValue="0" Name="rfCliente" SessionField="rfcliente" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Descr" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
还有一个下拉菜单,显示此gridview的项目。我使用下拉菜单过滤另一个gridview。 下拉列表:
<asp:DropDownList runat="server" ID="ddlCantiere" name="ddlCantiere" required="required" AppendDataBoundItems="true" placeholder="Filtra per cantiere" Width="20em" CssClass="ricerca" AutoPostBack="true">
<asp:ListItem Value="-1" Selected="True">Qualsiasi cantiere</asp:ListItem>
<asp:ListItem Value="1">Nessuno</asp:ListItem>
</asp:DropDownList>
gridview允许进行内联编辑,我想在用户编辑gridview的记录时刷新下拉列表。现在还没有。我尝试使用gridview的RowUpdated属性,但是在将更新的数据存储在数据库中之前会触发它,因此下拉列表会获取旧值。 如果用户在gridview中添加或删除记录,我还需要更新下拉列表。我该如何完成所有这一切?谢谢大家