C# 在EditItemTemplate gridview的下拉列表中获取预选文本
我无法在编辑模板的下拉列表中获取预选文本。请查看我的代码:C# 在EditItemTemplate gridview的下拉列表中获取预选文本,c#,asp.net,gridview,drop-down-menu,edititemtemplate,C#,Asp.net,Gridview,Drop Down Menu,Edititemtemplate,我无法在编辑模板的下拉列表中获取预选文本。请查看我的代码: <EditItemTemplate> <asp:DropDownList ID="droplist" runat="server"> </asp:DropDownList> </EditItemTemplate> 有人能告诉我应该怎么做才能得到预选下拉列表吗 问候 Hussain现在,您正在使用数据源中的选项填充DropDownList。但是,您没有将它的选定值绑定到任何对象
<EditItemTemplate>
<asp:DropDownList ID="droplist" runat="server">
</asp:DropDownList>
</EditItemTemplate>
有人能告诉我应该怎么做才能得到预选下拉列表吗
问候
Hussain现在,您正在使用数据源中的选项填充DropDownList。但是,您没有将它的选定值绑定到任何对象 无论您如何绑定Gridview中的其他字段,都要对DropDownList的SelectedValue进行绑定 在没有看到GridView标记的其余部分的情况下,我认为这样做应该可以:
<EditItemTemplate>
<asp:DropDownList ID="droplist" runat="server"
SelectedValue='<%# Bind("UnitID") %>' >
</asp:DropDownList>
</EditItemTemplate>
其中,上面的UnitID是GridView数据源中要绑定到DropDownList的SelectedValue的字段的名称。是否有任何错误?单击编辑按钮时无需任何错误。应使用该特定行的数据库值和所有预选行项一起预选dropdown。
<EditItemTemplate>
<asp:DropDownList ID="droplist" runat="server"
SelectedValue='<%# Bind("UnitID") %>' >
</asp:DropDownList>
</EditItemTemplate>