因此情況如此。 我在窗體視圖內的中繼器中有一個下拉列表。在表單視圖中的轉發器中從代碼隱藏設置下拉列表中選擇的值
真正特別的部分是中繼器正在被用來動態添加多行數據。
我一直在試圖做的和失敗的是設置下拉選定的值。
<asp:FormView ID="FormView3" runat="server" DataKeyNames="t_id"
DataSourceID="SqlDataSource25" DefaultMode="Insert">
<InsertItemTemplate>
t_p_id:
<asp:TextBox ID="t_p_idTextBox" runat="server" Text='<%# Bind("t_p_id") %>' />
<br />
t_step:
<asp:TextBox ID="t_stepTextBox" runat="server" Text='<%# Bind("t_step") %>' />
<br />
t_foreclosure_date:
<asp:TextBox ID="t_foreclosure_dateTextBox" runat="server"
Text='<%# Bind("t_foreclosure_date") %>' />
<br />
t_date:
<asp:TextBox ID="t_dateTextBox" runat="server" Text='<%# Bind("t_date") %>' />
<br />
<hr />
<asp:Repeater ID="repeater1" runat="server" OnPreRender="repeater1_PreRender" OnItemCommand="repeater1_ItemCommand" >
<HeaderTemplate>
<table cellpadding="5" cellspacing="5">
<tr style="padding-top: 5px;">
<td colspan="7">
<asp:Label ID="lblInstructions" runat="server" Text="Add entries here:" />
</td>
</tr>
<tr runat="server" id="trHeader" style="font-weight: bold;">
<td>Date</td>
<td>Cost</td>
<td>Type</td>
<td>Comment</td>
<td></td>
<td></td>
<td></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:TextBox ID="txtDate" runat="server" Width="55"
Text='<%#DataBinder.Eval(Container.DataItem, "date", "{0:d}")%>' /> </td>
<td><asp:TextBox ID="txtAmount" runat="server" Width="55"
Text='<%#DataBinder.Eval(Container.DataItem, "amount")%>' /> </td>
<td>
<asp:DropDownList ID="ddlType" runat="server" DataSourceID="SqlDataSource26"
DataTextField="tt_type" DataValueField="tt_id" ></asp:DropDownList>
</td>
<td><asp:TextBox ID="txtComment" runat="server" Width="300"
Text='<%#DataBinder.Eval(Container.DataItem, "comment")%>' /> </td>
<td style="text-align: center;">
<asp:Button ID="btnMoveUp" runat="server" Width="70"
Text="Move Up" CommandName="Up"
CommandArgument='<%# Container.ItemIndex %>' />
</td>
<td style="text-align: center;">
<asp:Button ID="btnMoveDown" runat="server" Width="90"
Text="Move Down" CommandName="Down"
CommandArgument='<%# Container.ItemIndex + 1 %>' />
</td>
<td style="text-align: center;">
<asp:Button ID="btnRemove" runat="server" Width="70"
Text="Remove" CommandName="Remove"
CommandArgument='<%# Container.ItemIndex %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr style="padding-top: 5px;">
<td colspan="6">
<asp:Button ID="btnAdd" runat="server"
Text="Add Row" CommandName="Add" />
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<hr />
<asp:CheckBoxList ID="tpTransmittalsDoclist" runat="server" DataSourceID="SqlDataSource13"
DataTextField="document_name" DataValueField="document_id">
</asp:CheckBoxList>
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
當代碼中的頁面加載後,我在第一個中繼行中插入虛擬值。我正在使用類費用設置/存儲中繼器行的值。但我不知道如何設置下拉列表中選中的數據綁定中繼器時的值。我嘗試了一些不同的東西,但沒有喜悅。有什麼想法嗎?
// load up costs in transmittals tab
if (!Page.IsPostBack)
{
Costs mycost = new Costs();
string date = DateTime.Now.ToShortDateString();
Costs.Cost cost1 = new Costs.Cost(date, "1.99", 2, "1");
mycost.Add(cost1);
Repeater r = FormView3.FindControl("repeater1") as Repeater;
r.DataSource = mycost;
r.DataBind();
}
編輯:如果您使用的是整數。你會想要使用。
SelectedIndex='<%#DataBinder.Eval(Container.DataItem, "type")%>'
最好的解決方案有時候是最簡單的。 Dangit我正在尋找類似的東西,但我找不到它。 尤達曼! – Prescient 2012-08-10 18:49:00
SelectedIndex ='<%#DataBinder.Eval(Container.DataItem,「type」)%>' 當處理整數 – Prescient 2012-08-20 13:52:58