看起来这应该很简单,但我很困惑。我已经设置好我的 ListView 并绑定(bind)到我的 LINQ 数据源。来源取决于下拉列表,该列表决定在 ListView 中显示哪些分支信息。我的编辑模板工作正常,但我的插入模板不起作用,因为它需要我想从 ListView 外的下拉列表中获取的分支 ID,但我不知道如何绑定(bind)该值并将其设置在我的模板中。它看起来像这样:
<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>
我需要在其中获取一个标签,该标签绑定(bind)到 ListView 外部的数据绑定(bind) asp 下拉列表的值,以便插入工作。
最佳答案
使用 DropDownList 的 OnSelectedIndexChanged(具有 AutoPostBack=True)回调,在 DropDownList 的值更改时手动将 ListView 中的值设置为该分支的默认值。
protected void BranchDropDownList_OnSelectedIndexChanged( object sender, EventArgs e )
{
DropDownList ddl = (DropDownList)sender;
RechargeRateTextBox.Text = BranchManager.GetRechargeRate( ddl.SelectedValue );
}
将整个事情包装在一个 UpdatePanel 中,这一切都可以通过 AJAX 发生。
关于c# - 带有 LINQ 数据源插入模板的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/212257/