在gridview中查看下拉列表值(visual studio 2012)

时间:2014-09-18 06:44:30

标签: sql asp.net vb.net

我有两个表dbo.rank(rankID,rankName)和dbo.tbStaff(Staff ID,RankID,StaffName)。并且下拉列表显示rankName。但在gridview中它显示了rankID。如何使其显示在下拉列表中的rankName。请帮助!!!

这是我的下拉列表代码:

<asp:DropDownList ID="DropDownList1" runat="server" Height="29px" style="margin-left: 53px" Width="422px" 
DataSourceID="SqlDataSource1" DataTextField="RankName" DataValueField="RankID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProjectSPConnectionString %>"
SelectCommand="SELECT [RankID],[RankName] FROM [tbRank] ORDER BY [RankID]" 
ProviderName="<%$ ConnectionStrings:ProjectSPConnectionString.ProviderName %>">
</asp:SqlDataSource>

我的gv:

                                                                 

1 个答案:

答案 0 :(得分:0)

你必须自定义你的网格试试这个

        <asp:GridView ID="gvStaff" runat="server" AutoGenerateColumns ="false">
        <Columns>
            <asp:TemplateField HeaderText="ID">
                <ItemTemplate>
                    <asp:Label Text='<%# Eval("RankID") %>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField  HeaderText="Name">
                <ItemTemplate>
                    <asp:Label Text='<%# Eval("RankName") %>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>