本文介绍了如何设置的DropDownList的SelectedValue的GridView控件中EditTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的this正如前面问道。我发现的唯一区别是,被列入上述code额外的列表项。

I am trying to do this as asked earlier. The only difference that I found is additional List item that was included in above code.

我试图用 AppendDataBoundItems = TRUE 但它仍然没有工作。我也想设置的默认值的ItemTemplate中即被显示在标签中的值DropDownList的的SelectedValue ='<%#的eval(DepartmentName的)%> 但thie属性不DropDownList中提供给我。
可能是什么原因。 ??

I tried to use AppendDataBoundItems=true but it is still not working. I also want to set the its default value to the value that was being displayed in label of itemtemplate i.e. DropDownList's SelectedValue='<%# Eval("DepartmentName") %>' but thie property is not available to me in dropdownlist.What could be the reason. ??

<EditItemTemplate>
    <asp:DropDownList ID="ddlDepartment_Edit" runat="server" 
        DataSourceID="dsDepartment_Edit" DataTextField="DepartmentName" 
        DataValueField="PK_DepartmentId">
    </asp:DropDownList>
    <asp:SqlDataSource ID="dsDepartment_Edit" runat="server" 
        ConnectionString="<%$ ConnectionStrings:BlackHillsConnect %>"  
        ProviderName="System.Data.SqlClient" SelectCommand="sp_GetDepartmentDropDown" 
        SelectCommandType="StoredProcedure">
    </asp:SqlDataSource>                                 
</EditItemTemplate>
<ItemTemplate>
    <asp:Label ID="lblDepartmentName" runat="server" Text='<%# Eval("DepartmentName") %>' >
    </asp:Label>
</ItemTemplate>   

我使用 GridView控件

推荐答案

DataValueField 似乎是错误的 - 应该不会是的DepartmentID ?同样的,你需要有的SelectedValue ='&LT;%#的eval(**的DepartmentID **)%&GT; - DepartmentName的将是 SeletectText

DataValueField seems to be wrong - shouldn't it be DepartmentId? Similarly, you need to have SelectedValue='<%# Eval("**DepartmentId**") %>' - DepartmentName would be the SeletectText.

这篇关于如何设置的DropDownList的SelectedValue的GridView控件中EditTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:22