2008-10-17 27 views
1

看起來這應該是直截了當的,但我很驚訝。我有我的列表查看所有設置並綁定到我的LINQ數據源。源依賴於下拉列表,該列表決定哪個分支信息在列表視圖中顯示。我的編輯模板工作正常,但我的插入模板將無法正常工作,因爲它想要從列表視圖外的下拉列表中獲取分支ID,但我不知道如何綁定該值並將其設置在我的模板中。它看起來像這樣:帶有LINQ數據源插入模板的ListView

<InsertItemTemplate> 
    <tr style=""> 
     <td> 
     <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
       Text="Insert" /> 
    </td> 
     <td> 
     <asp:TextBox ID="RechargeRateTextBox" runat="server" 
      Text='<%# Bind("RechargeRate") %>' /> 
     </td> 
       <td> 
     <asp:Calendar SelectedDate='<%# Bind("StartDate") %>' ID="Calendar1" runat="server"></asp:Calendar>          
     </td> 
      </tr> 
    </InsertItemTemplate> 

我需要得到一個標籤那裏,結合數據綁定的ASP下拉列表的值列表視圖之外,使得插入會工作。

回答

1

我結束了這一切,謝謝twanfosson。

protected void ListView1_ItemInserting(object sender, System.Web.UI.WebControls.ListViewInsertEventArgs e) 
     { 
      e.Values["BranchID"] = DropDownList1.SelectedValue; 
     } 
4

使用DropDownList的OnSelectedIndexChanged(with AutoPostBack = True)回調可以在DropDownList的值更改時手動將ListView中的值設置爲該分支的默認值。

protected void BranchDropDownList_OnSelectedIndexChanged(object sender, EventArgs e) 
{ 
    DropDownList ddl = (DropDownList)sender; 
    RechargeRateTextBox.Text = BranchManager.GetRechargeRate(ddl.SelectedValue); 
} 

把整個東西包裝在一個UpdatePanel中,它可以通過AJAX發生。