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

  • SEARCH
  • Home
  • 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 8270031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:25:59+00:00 2026-06-08T06:25:59+00:00

I am trying to get a gridview to populate text from the database call

  • 0

I am trying to get a gridview to populate text from the database call to my Label as shown
The Results have been tested and are returning the correct names

protected void Page_Load(object sender, EventArgs e)
{
    DataTable t = DBProductLink.ListWithOptions(ProductId, LinkType, null);
    TestList.DataSource = t ;
    TestList.DataBind();
}

The labels are created in the Gridview like this:

<asp:GridView ID="TestList" runat="server" OnRowDataBound="testDataBound" AutoGenerateColumns="false" DataKeyNames="Id">
    <Columns>
        <asp:TemplateField HeaderText="Sizes">
            <asp:ItemTemplate>
                <asp:Label ID="sizeLabel" runat="server" Text='<%# Eval("size") %>' />
            </asp:ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

I then tried to loop through the gridview and access the label using the ondatarowbound, however in this it is null.

protected void testDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType != DataControlRowType.DataRow)
        return;

    Label sizeLabel = e.Row.FindControl("sizeLabel") as Label;
    sizeLabel.Text = "test";
}

I am using the exact same set up with 2 drop boxes and 2 labels on another gridview with a different name on the same page which is not having this problem. Anyone got an idea on this?
The other Gridview is as follows:

<asp:GridView ID="SearchList" runat="server" AutoGenerateColumns="False"
    DataKeyNames="Id"  OnRowDataBound="SearchList_RowDataBound"
    OnRowCommand="SearchList_RowCommand" Width="100%"  PageSize="20" >
    <Columns>
        <asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
        <asp:TemplateField HeaderText="Price" SortExpression="Price">
            <ItemTemplate>
                <robo:MoneyLabel ID="MoneyLabel2" runat="server" 
                    Value='<%# Eval("Price") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Type">
            <ItemTemplate>
                <asp:Label ID="typeLabel" runat="server" Text='<%# Eval("Type") %>' />
                <asp:HiddenField ID="productId" runat="server" Value='<%# Eval("Id") %>' />
                <asp:HiddenField ID="isFabric" runat="server" Value='<%# Eval("IsFabric") %>' />
                <asp:HiddenField ID="isOldWizard" runat="server" Value='<%# Eval("IsOldWizard") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Options/Color/Size">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="GetOptions" Text="Get Options" CausesValidation="false" CommandName="Options"  />
                <asp:Label ID="OptionLabel" Visible="false" runat="server" Text="Option: " />
                <asp:DropDownList ID="ProductOptions" runat="server" Visible="false" />
                <asp:Label ID="ColorLabel" Visible="false" runat="server" Text="Color: "  />
                <asp:DropDownList  ID="RibbonColors" runat="server" Visible="false" AutoPostBack="true" />&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="SizeLabel" Visible="false" runat="server" Text="Size: " />
                <asp:DropDownList ID="RibbonSizes" runat="server" Visible="false" AutoPostBack="true"  />
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Add">
            <ItemStyle Width="60px" />
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" Text="Add" CommandName="Add" CommandArgument='<%# Eval("Id") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

.cs is

protected void SearchList_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType != DataControlRowType.DataRow)
        return;
    int productId = (int)SearchList.DataKeys[e.Row.RowIndex].Value;
    LinkButton GetOptions = e.Row.FindControl("GetOptions") as LinkButton;
    DropDownList RibbonColors = e.Row.FindControl("RibbonColors") as DropDownList;
    DropDownList  RibbonSizes = e.Row.FindControl("RibbonSizes") as DropDownList;
    DropDownList ProductOptions = e.Row.FindControl("ProductOptions") as DropDownList;
    Label typeLabel = e.Row.FindControl("typeLabel") as Label;
    HiddenField isFabric = e.Row.FindControl("isFabric") as HiddenField;
    HiddenField isOldWizard = e.Row.FindControl("isOldWizard") as HiddenField;

    ProductType typeValue = DBConvert.ToEnum<ProductType>(typeLabel.Text);
    bool isFabricValue = Convert.ToBoolean(isFabric.Value.ToString());
    bool isOldWizardValue = Convert.ToBoolean(isOldWizard.Value.ToString());       
}
  • 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-08T06:26:01+00:00Added an answer on June 8, 2026 at 6:26 am

    I just found the problem

    Your markup is wrong it was tricky… I admit it

    This tag: <asp:ItemTemplate> should be <ItemTemplate>

    Change this:

    <asp:TemplateField HeaderText="Sizes">
        <asp:ItemTemplate>
             <asp:Label ID="sizeLabel" runat="server" Text='<%# Eval("size") %>' />
        </asp:ItemTemplate>
    </asp:TemplateField>
    

    Into

    <asp:TemplateField HeaderText="Sizes">
        <ItemTemplate>
             <asp:Label ID="sizeLabel" runat="server" Text='<%# Eval("size") %>' />
        </ItemTemplate>
    </asp:TemplateField>
    

    This should raise an exception… but instead, the ItemTemplate was completely ignored

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

Sidebar

Related Questions

I have a gridview, and I'm trying to get the text value of a
I'm trying to insert values from gridview to a database but I get error:
So I'm trying to update my GridView, and I get this error: You have
I have been trying to get SqlCacheDependency working. I think I have everything set
Im trying to get a completly data copy from a gridview, itryed clone(), tryed
I'm trying to get the text of a HyperLinkField in a GridView's OnRowDelete event
I am trying to get a parameter for my update from the gridview but
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I have six imageViews in my gridview. I am trying to get the focus
I have a problem, into my project i'm trying to get data from my

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.