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 7743281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:29:36+00:00 2026-06-01T09:29:36+00:00

I know the question I’m going to ask is already asked for by other

  • 0

I know the question I’m going to ask is already asked for by other people, but those answers are no solution for my problem.

I have a gridview containing 2 BoundFields, 2 ButtonFields and a checkbox field (which is a TemplateField).

I also have a datatable, filled with data from the database.

In the aspx code I create my gridview with the fields set the last BoundField Visible = false.

In my codebehind, I add the colums and bind the datasource to my datatable.

But when I try to read the data from the hidden boundfield, that field is empty. The problem why I can’t use the solutions mentioned with similar questions, is because the people assume the data gets filled in one by one, and not by binding a datatable to the datasource of the gridview.

So my question is: Is their a way to get the data from the hidden boundfield and also retain the possibility to add the data by binding the datatable to the datasource of the gridview?
And if so, is it posible to get the value from that field?

p.s. I’m using asp.net/c# in visual studio 2010

ASPX:

<asp:GridView ID="gvSelect" runat="server" AutoGenerateColumns="False" BorderStyle="None" onrowcommand="gvTestSelect_RowCommand">
    <Columns>
        <asp:TemplateField>
            <HeaderTemplate>
                <asp:CheckBox runat="server" ID="cbHeader" OnPreRender="cbHeader_PreRender" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox runat="server" ID="cbItems" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="field" HeaderText="Veld" SortExpression="field" />
        <asp:ButtonField DataTextField="up" HeaderText="Omhoog" SortExpression="up" CommandName="up" Text="&uarr;" />
        <asp:ButtonField DataTextField="down" HeaderText="Omlaag" SortExpression="down" CommandName="down" Text="&darr;" />
        <asp:BoundField DataField="hidden" SortExpression="hidden" />
    </Columns>
</asp:GridView>

Code Behind (where I fill the gridview):

//create array list and fill it with all columns
Dictionary<string, string> dict = FillLists.getColumnsByTable(loader, ddlInfoTableI.SelectedItem.Value.ToString());

//loop trough dictionary
foreach (var val in dict)
{
    //create new dtSelect datarow
    DataRow dr = dtSelect.NewRow();

    //set row values for column values
    dr["select"] = false;
    dr["field"] = val.Value.ToString();
    dr["up"] = new ButtonField { CommandName = "up", Text = loader.LoadResourceString(1024), HeaderText = "&uarr;", ButtonType = ButtonType.Button, Visible = true };
    dr["down"] = new ButtonField { CommandName = "down", Text = loader.LoadResourceString(1025), HeaderText = "&darr;", ButtonType = ButtonType.Button, Visible = true };
    dr["hidden"] = val.Key.ToString();

    //add the datarow
    dtSelect.Rows.Add(dr);

    //set datatable session to datatable
    Session["dtSelect"] = dtSelect;

    //set datasource of the gridview to datatable
    gvSelect.DataSource = dtSelect;

    //bind data to gridview
    gvSelect.DataBind();
}

So now I need to get the data from the gridview (escpecialy from the hidden boundfield), because they can edit the gridview except the hidden boundfield, so that is the only way to know which original row it was.

  • 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-01T09:29:37+00:00Added an answer on June 1, 2026 at 9:29 am

    Add a data key for the column you need to get:

    <asp:GridView ID="GridView1" runat="server" DataKeyNames="hidden" ...>
    

    Once you’ve added the datakey, you can access its value with the row index:

    var rowIndex = 0;
    var hiddenValue = (string)GridView1.DataKeys[rowIndex]["hidden"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked a few other times but I have
I know this question would have been asked several time but still I am
I know this question has been asked before, but none of the previous answers
I know this question has been asked before, but I ran into a problem.
I know a question like this was already asked, but the situation is a
I know this question was asked before but I have the following simple code
I know this question has probably been asked already but I would really like
I know this question has been asked before, but I have tried the given
I know this question has been done but I have a slightly different twist
I know the question is a little choppy and perhaps misleading,but I have a

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.