質問

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