Question

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?

Was it helpful?

Solution

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

<%# ((KeyValuePair<string, string>)Eval("AddressType")).Value %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top