我的gridview有点问题。 在Editmode中,我加载了一个包含来自我的数据库的内容的下拉列表(外键!)。 当我保存更改并在编辑视图中再次执行后,下拉列表会显示表中的第一个条目,而不是保存的值中的值。当我进入editmode时,如何在下拉列表中将默认值设置为数据库中设置的值?
我希望我的担忧是可以理解的。非常感谢您的帮助!
我的代码(简称)
<asp:DetailsView ID="dtvProjektdetails" runat="server" DataSourceID="sqlProjectDetails" AutoGenerateRows="False" DataKeyNames="ProjectID" DefaultMode="Edit" onitemupdating="dtvProjektdetails_ItemUpdating">
<Fields>
<asp:TemplateField HeaderText="Segment" SortExpression="FK_Segment">
<EditItemTemplate>
<asp:DropDownList ID="ddlSegment" runat="server" DataSourceID="sqlDSSegment" DataTextField="Segment" DataValueField="SegID">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
下拉数据源(简称)
<asp:SqlDataSource ID="sqlDSSegment" runat="server" ConnectionString="<%$ ConnectionStrings:CSLinker %>" SelectCommand="SELECT * FROM [tabSegment] ORDER BY Segment]"></asp:SqlDataSource>
Detailview的数据源:
<asp:SqlDataSource ID="sqlProjectDetails" runat="server"
ConnectionString="<%$ ConnectionStrings:CSLinker %>"
SelectCommand="SELECT * FROM [tabProjects] WHERE ([ProjectID] = @ProjectID)"
UpdateCommand="UPDATE [tabProjects] SET [Name] = @Name, [ProejctNo] = @ProejctNo, [Startdate] = @Startdate, [Enddate] = @Enddate, [FK_Owner] = @FK_Owner, [FK_Segment] = @FK_Segment, [FK_ProjectCategorie] = @FK_ProjectCategorie, [FK_ProjectFiles] = @FK_ProjectFiles, [FK_Mailings] = @FK_Mailings, [Botschaft] = @Botschaft, [Ziel] = @Ziel, [Callmenge] = @Callmenge, [Quote] = @Quote, [Zielgruppe] = @Zielgruppe, [Inboundnummer] = @Inboundnummer, [Wissen] = @Wissen, [Prozess] = @Prozess, [Goodies] = @Goodies, [FK_Sprachen] = @FK_Sprachen WHERE [ProjectID] = @ProjectID">
<SelectParameters>
<asp:ControlParameter ControlID="lblPID" Name="ProjectID" PropertyName="Text" Type="Int64" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ProejctNo" Type="String" />
<%--<asp:Parameter Name="Description" Type="String" />--%>
<asp:Parameter Name="Startdate" Type="DateTime" />
<asp:Parameter Name="Enddate" Type="DateTime" />
<asp:Parameter Name="FK_Owner" Type="Int64" />
<asp:Parameter Name="FK_Segment" Type="Int64" />
<asp:Parameter Name="FK_ProjectCategorie" Type="Int64" />
<asp:Parameter Name="FK_ProjectFiles" Type="Int64" />
<asp:Parameter Name="FK_Mailings" Type="Int64" />
<asp:Parameter Name="Botschaft" Type="String" />
<asp:Parameter Name="Ziel" Type="String" />
<asp:Parameter Name="Callmenge" Type="String" />
<asp:Parameter Name="Quote" Type="String" />
<asp:Parameter Name="Zielgruppe" Type="String" />
<asp:Parameter Name="Inboundnummer" Type="String" />
<asp:Parameter Name="Wissen" Type="String" />
<asp:Parameter Name="Prozess" Type="String" />
<asp:Parameter Name="Goodies" Type="String" />
<asp:Parameter Name="FK_Sprachen" Type="Int64" />
<%--<asp:Parameter Name="FK_Agenten" Type="Int64" />--%>
<asp:Parameter Name="ProjectID" Type="Int64" />
</UpdateParameters>
</asp:SqlDataSource>
答案 0 :(得分:2)
设置下拉列表的selectedvalue - 属性:
<asp:DropDownList ID="ddlLinkCategorie" runat="server" DataSourceID="sqlDScategorie"
DataTextField="Categorie" DataValueField="LinCatID" selectedvalue='<%Bind("columnName")%>'>
</asp:DropDownList>