How to update a dropdownlist inside an Ajax modal popup panel
I have a girdview in side an update panel, the girdview allows to edit, delete the data in my database, I have button named Insert, when the insert button is clicked, an ajax model popup panel will show up, inside that pop up panel, there is a dropdownlist.
My question is that how can I update the dropdownlist inside the popup panel every time there is a change in my girdview panel.
I tried changing some data in the girdview, then I have to refresh the whole paper(thing which I don't want to do) to update the dropdownlist.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Test.aspx.cs" Inherits="Pages" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button ID="RegisterButton" runat="server" Text="Register" OnClick="callmethod" />
<asp:ScriptManager ID="ScriptManager" runat="server">
</asp:ScriptManager>
<asp:Panel ID="MainPanel" runat="server" Style="display: none" CssClass="modalPopup">
<div>
<asp:Table ID="InputTable" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="LabelName" runat="server" Text="name"> </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="TName" runat="server"></asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:RequiredFieldValidator ID="NameRequiredFieldValidator" ControlToValidate="TName"
runat="server" ErrorMessage="RequiredFieldValidator">Cannot be Empty</asp:RequiredFieldValidator>
</asp:TableCell>
<asp:TableCell><asp:DropDownList ID="TProjectMID" runat="server"> </asp:DropDownList></asp:TableCell>
</asp:TableRow>
</asp:Table>
<p style="text-align: center;">
<asp:Button ID="OkButton" runat="server" Text="OK" UseSubmitBehavior="false" OnClick="OkButton_Click" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
</p>
</div>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server" TargetControlID="RegisterButton"
BackgroundCssClass="modalBackground" PopupControlID="MainPanel" OkControlID="OkButton"
OnOkScript="onOk()" CancelControlID="CancelButton" PopupDragHandleControlID="InfoPanel" />
<asp:UpdatePanel ID="UpdatePane" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="ProjectID" DataSourceID="DataSource"
Width="921px">
<Columns>
<asp:CommandField ShowDeleteButton="True" CausesValidation="false" causeValidation = "false"/>
<asp:BoundField DataField="ID" HeaderText="ProjectID" SortExpression="ProjectID"
ReadOnly="True" />
<asp:BoundField DataField="Name" HeaderText="ProjectName" SortExpression="ProjectName" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="DataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DeleteProject" DeleteCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="original_ID" Type="String" />
<asp:Parameter Name="original_Name" Type="String" />
</DeleteParameters>
</asp:SqlDataSource>
</ContentTemplate>
<开发者_运维百科/asp:UpdatePanel>
Dynamically populate your dropdown list with AJAX. Or does .net have anyway you can bind a dropdown to a gridview. Last time i used it was 2.0. :)
Why can't you bind the DropDownlist to it's DataSource every time the user clicks on the Insert-Button? You should also wrap the content of the popup in its own UpdatePanel and only Update
it when the popup is shown ot ensure that only the popup will be reloaded and not the whole page.
Edit:
The reason for the missing postback could be that any Validator is blocking it. Set CausesValidation=false
to your Register-Button that opens the Popup. Another point: because the button is outside of the UpdatePanel UpdatePane
, i would consider to create an AsyncPostBacktrigger with the RegisterButton
as ControlID
.
精彩评论