代码之家  ›  专栏  ›  技术社区  ›  Echostorm

具有LINQ数据源插入模板的ListView

  •  1
  • Echostorm  · 技术社区  · 17 年前

    看起来这应该是直截了当的,但我觉得难以置信。我已将listview全部设置并绑定到我的LINQ数据源。源依赖于一个下拉列表,该列表决定在listview中显示哪个分支信息。我的编辑模板工作正常,但我的插入模板无法工作,因为它需要我想从listview之外的dropdownlist中获取的分支ID,但我不知道如何绑定该值并在模板中设置它。看起来是这样的:

    <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>
    

    我需要在其中获得一个标签,该标签绑定到listview外部的数据绑定asp dropdownlist的值,以便插入可以工作。

    2 回复  |  直到 17 年前
        1
  •  4
  •   tvanfosson    17 年前

    当DropDownList的值更改时,使用DropDownList的OnSelectedIndexChanged(AutoPostBack=True)回调将ListView中的值手动设置为该分支的默认值。

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

    将整个过程封装在UpdatePanel中,所有这些都可以通过AJAX实现。

        2
  •  1
  •   Echostorm    17 年前

    我最终还是做了这个,谢谢twanfosson。

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