In ASPX File

   <asp:GridView ID="gvSavedAddresses" runat="server">
    <Columns>
    <asp:TemplateField SortExpression="AddressType" ItemStyle-Width="9%" HeaderText="Type"
     HeaderStyle-ForeColor="Black">
   <ItemTemplate>
    <asp:Label runat="server" ID="lblAddressType" Text='<%#Eval("AddressType")%>'> 
    </asp:Label>
  </ItemTemplate>
  </asp:TemplateField>
   </Columns>
  </asp:GridView>

In CS File

objAddr.AddressType = new KeyValuePair<string, string>(dr["AddressTypeLookupID"].ToString(), dr["AddressType"].ToString());

I want to display only Value in the grid. But in my code it is showing both key and value in grid cell. how to avoid this?

有帮助吗?

解决方案

Cast the field to its actual type, and retrieve Value:

<%# ((KeyValuePair<string, string>)Eval("AddressType")).Value %>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top