我正在尝试从EditItemTemplate中的ListView中的DropDownList绑定数据,但它不起作用。
代码:
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("type")%>'>
<asp:ListItem Text="Fatwa" Value="1"></asp:ListItem>
<asp:ListItem Text="Interviewer" Value="2"></asp:ListItem>
<asp:ListItem Text="Programs" Value="3"></asp:ListItem>
</asp:DropDownList>
答案 0 :(得分:0)
以下是您可以使用的概念示例:
<EditItemTemplate>
<asp:Label ID="DataLabel" runat="server" Text="<% $resources:AppResource,UserData %>"
CssClass="OneColumnTitleLabel"></asp:Label>
<br />
<br />
<asp:Label ID="EmailLabel" CssClass="RightColumnLabel" runat="server" Text='<%# Resources.AppResource.Email + ":" %>'></asp:Label><br />
<asp:TextBox ID="EmailTextBox" runat="server" CssClass="RightColumnText" Text='<%# Eval("Email") %>'
ReadOnly="true"></asp:TextBox>
<br />
<asp:Label ID="LanguageLabel" CssClass="RightColumnLabel" runat="server" Text='<%# Resources.AppResource.Language + ":" %>'></asp:Label><br />
<asp:DropDownList ID="LanguageDropDown" runat="server" CssClass="RightColumnDropDown"
DataSourceID="LanguageDataSource" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("LanguageId") %>'
AppendDataBoundItems="True">
<asp:ListItem Value="" Text="" Selected="True">
</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label2" CssClass="RightColumnLabel" runat="server" Text='<%# Resources.AppResource.Company + ":" %>'></asp:Label><br />
<asp:TextBox ID="CompanyTextBox" runat="server" CssClass="RightColumnText" Text='<%# Bind("Company") %>'></asp:TextBox>
<br />
<asp:Label ID="PhoneLabel" CssClass="RightColumnLabel" runat="server" Text='<%# Resources.AppResource.Phone + ":" %>'></asp:Label><br />
<asp:TextBox ID="PhoneTextBox" runat="server" CssClass="RightColumnText" Text='<%# Bind("Phone") %>'></asp:TextBox>
<br />
<asp:Button ID="UpdateUserData" runat="server" Text='<%# Resources.AppResource.Save %>'
CssClass="Button" CommandName="Update" CausesValidation="true" />
</EditItemTemplate>
注意LanguageDropDown(LanguageId被绑定回listview)。此下拉列表绑定到数据源,如下所示:
<asp:ObjectDataSource ID="LanguageDataSource" runat="server" SelectMethod="GetLanguages"
TypeName="GP.Solutions.Services.LanguageManager"></asp:ObjectDataSource>
这是你可以在listview中绑定下拉列表的方法。
答案 1 :(得分:0)
我的代码运行良好,但我忘记在listview中键入DataKeyNames:D
<asp:ListView ID="TodayOrdersList" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ID">