2014-01-23 79 views
0

內部窗體視圖我有選定的索引更改下拉列表我有文本框出現。 現在我想將這些下拉菜單和文本框保留在Ajax更新面板中。點擊按鈕後,我更想保存這兩個字段。asp.net窗體視圖的Ajax

任何幫助非常感謝。

這裏的aspx代碼

<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' /> 
        <br /> 
        <asp:DropDownList ID="ddlLName" 
         runat="server" ValidationGroup="VG1" SelectedValue='<%# Bind("LNAMEIFYES") %>' OnSelectedIndexChanged="ddlLName_SelectedIndexChanged" AutoPostBack="True"> 
         <asp:ListItem Value="">Please select...</asp:ListItem> 
         <asp:ListItem Value="1">Yes</asp:ListItem> 
         <asp:ListItem Value="2">No</asp:ListItem> 

        </asp:DropDownList> 
        <br /> 
        <asp:Panel ID="pnlLNAme" runat="server" Visible="false"> 
         LName: 
        <asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' /> 
         <br /> 
        </asp:Panel> 

代碼隱藏

protected void ddlLName_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     DropDownList ddlLName = (DropDownList)FormView1.FindControl("ddlLName"); 
     if (ddlLName.SelectedValue == "1") 
     { 
      Panel pnlLNAme = (Panel)FormView1.FindControl("pnlLNAme"); 
      pnlLNAme.Visible = true; 

     } 
     else 
     { 
      Panel pnlLNAme = (Panel)FormView1.FindControl("pnlLNAme"); 
      pnlLNAme.Visible = false; 

     } 
    } 
+0

顯示您到目前爲止的代碼 –

+0

我已更新的問題來添加代碼。 – Sajid

回答

1

我通過使用兩個更新panals,在更新PANAL的一個使用觸發器使用解決了這個問題。

<EditItemTemplate> 
       <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
        <ContentTemplate> 
         ID: 
      <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' /> 
         <br /> 
         Name: 
      <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' /> 
         <br /> 
         <asp:DropDownList ID="ddlLName" 
          runat="server" ValidationGroup="VG1" SelectedValue='<%# Bind("LNAMEIFYES") %>' OnSelectedIndexChanged="ddlLName_SelectedIndexChanged" AutoPostBack="True"> 
          <asp:ListItem Value="">Please select...</asp:ListItem> 
          <asp:ListItem Value="1">Yes</asp:ListItem> 
          <asp:ListItem Value="2">No</asp:ListItem> 

         </asp:DropDownList> 
         <br /> 
         <asp:Panel ID="pnlLNAme" runat="server" Visible="false"> 
          LName: 
       <asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' /> 
          <br /> 
         </asp:Panel> 
        </ContentTemplate> 
       </asp:UpdatePanel> 
       <asp:UpdatePanel ID="UpdatePanel2" runat="server"> 
        <ContentTemplate> 
         Salary: 
      <asp:TextBox ID="SalaryTextBox" runat="server" Text='<%# Bind("Salary") %>' /> 
         <br /> 
         IsActive: 
      <asp:CheckBox ID="IsActiveCheckBox" runat="server" Checked='<%# Bind("IsActive") %>' /> 
         <br /> 
         <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> 
         &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> 
        </ContentTemplate> 
        <Triggers> 
         <asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click_Enent" /> 
        </Triggers> 
       </asp:UpdatePanel> 
      </EditItemTemplate> 
相關問題