简体   繁体   中英

aspx bind data with '#' symbol to gridview

Been trying to fix this for hours and I know that the problem is with the '#' but I could not find any solution to this problem. My field name in the database is 'HRTRN#'.

<asp:TemplateField HeaderText="Transaction#">
   <EditItemTemplate>
      <asp:TextBox ID="TextBox13" runat="server" Text='<%# Bind("HRTRN#") %>'   Width="50px" Height="17px" MaxLength="14"></asp:TextBox>
   </EditItemTemplate>

  <ItemTemplate>
       <asp:Label ID="Label5" runat="server" Text='<%# Bind("HRTRN#") %>'></asp:Label>
  </ItemTemplate>
</asp:TemplateField>

Does anyone know the solution for this to make the field name containing # symbol accessible?

You should change your code from :

Bind("HRTRN#")

To

Bind("[HRTRN#]")

Since it contains special charcters. ( you would do that also for columns with spaces).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM