Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:41:12+00:00 2026-06-10T10:41:12+00:00

I have the following GridView , which has as DataSource a List<T> : <asp:GridView

  • 0

I have the following GridView, which has as DataSource a List<T>:

<asp:GridView ID="gvDownloads" UseAccessibleHeader="False"
              AutoGenerateColumns="False" runat="server" PageSize="10" AllowPaging="true" 
              CellPadding="4" CellSpacing="1" GridLines="None" DataKeyNames="productid">
             <EmptyDataTemplate>
                No licenses found 
             </EmptyDataTemplate>
             <Columns>
                <asp:TemplateField HeaderText="Id" >
                   <ItemTemplate>
                       <%# Eval("ProductId")%>
                   </ItemTemplate>
                </asp:TemplateField> 
                <asp:TemplateField HeaderText="Product Name">
                   <ItemTemplate>
                       <%# Eval("ProductName")%>
                   </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Stock Code">
                   <ItemTemplate>
                       <%# Eval("StockCode")%>
                   </ItemTemplate>
                </asp:TemplateField>
            </Columns>
</asp:GridView>

Which renders correctly and with the proper values.

Now, I would like to modify on the fly the field StockCode and in order to do so I have in my code behind:

Sub gvDownloads_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvDownlads.RowDataBound

    If e.Row.RowType = DataControlRowType.DataRow Then

         e.Row.Cells(2).Text = StockCodeConverter.Convert(e.Row.Cells(2).Text)

    End If
End Sub

But the data cells corresponding to StockCode are empty. Now I tried to debug and for some reason the code finds just the value of the header row. The values of the other rows are string.Empty or &nsbp. Might it depend on the List as DataSource?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:41:14+00:00Added an answer on June 10, 2026 at 10:41 am

    Use ASP.NET controls instead, for example Labels:

    If e.Row.RowType = DataControlRowType.DataRow Then
         Dim lblStockCode = DirectCast(e.Row.FindControl("lblStockCode"), Label)
        lblStockCode.Text = StockCodeConverter.Convert(lblStockCode.Text)
    End If
    

    on aspx:

    <asp:TemplateField HeaderText="Stock Code">
        <ItemTemplate>
            <asp:Label Id="LblStockCode" runat="server" Text='<%# Eval("StockCode") %>'></asp:label>
        </ItemTemplate>
    </asp:TemplateField>
    

    You can even omit the Eval on aspx and set the Text property completely in codebehind:

    If e.Row.RowType = DataControlRowType.DataRow Then
         Dim row = DirectCast(e.Row.DataItem, DataRowView)
         Dim lblStockCode = DirectCast(e.Row.FindControl("lblStockCode"), Label)
        lblStockCode.Text = StockCodeConverter.Convert(row["StockCode"].ToString)
    End If
    

    Edit: If you want to stay with your text and also with the TemplateField you could cast the first control in the cell which is a autogenerated DataBoundLiteralControl when there’s only text and use it’s Text property.

    Dim StockCode = DirectCast(e.Row.Cells(2).Controls(0), DataBoundLiteralControl).Text
    

    But that makes your code less readable in my opinion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following aspx: <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False BorderStyle=None Font-Names=Verdana Font-Size=12px OnSelectedIndexChanged=GridView1_SelectedIndexChanged ShowHeader=False
I have following Gridview: <asp:GridView ID=GridView1 runat=server CssClass=table DataKeyNames=groupId DataSource=<%# dsUserGroupsSelected %> DataMember=Group etc....>
I have the following structure in an aspx page: <asp:Panel ID=pnlCust runat=server> <asp:GridView ID=gvMaster
I have a GridView which has following template field that holds the filename, when
I have an ASP.NET GridView which is populated from a SQL Server database. This
I have an ASP.NET GridView that's bound to an ObjectDataSource (which is bound to
On an ASP NET project I have a gridview control with the following information:
I have the following code which adds a label and a gridview to an
i have a gridview which has one of the columns as a dropdown. When
I have a GridView which I bind to a SqlDataReader on Page_Load. It has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.