0

I have a gridview which contains columns of my desire to display. But I want to access a value for data row of a gridview which is not displayed in gridview but it is in datatable for that particular row.
Initially what I did is display it to gridview as well as I accessed its value using index, but I really don't want to display its value in gridview. In that case I set visible=false but then it doesn't recognize to cell so what should I do to achieve this?
Please let me know so that I don't have to display that particular row and I can access the value for that row which do exist in data table.

2
  • What do you plan to do with that value? Can you store the value in a cookie? Commented Aug 28, 2010 at 11:13
  • Your question is unclear as to whether you are talking about a column you don't want displayed, or a completely separate row of data. Clarify please? Commented Aug 29, 2010 at 6:35

2 Answers 2

1

You can access all column values if you set their visible="false" , In this situation You need to set datakey name for your gridview .

    //In GridView RowCommand Event:
    int index = Convert.ToInt32(e.CommandArgument);

    //If we have more than one DataKeys ( ItemId is the field that is visbile = false and myGridView.DatakeyName = Itemid)
    int ItemId = Convert.ToInt32(GridView1.DataKeys[index].Values["ItemId"]);
    //else
    int ItemId = Convert.ToInt32(GridView1.DataKeys[index].Value);

If your desired column is not datakey , So you can use gridViewRow

  GridViewRow row = GridView1.Rows[index];

and Then you can access all the column of that row .

Hope this help

Sign up to request clarification or add additional context in comments.

Comments

0

Are you trying to use this for something like a primary key from the table? Here's a blog post I wrote a couple years ago that explains how you can leverage a field like this from the database without it displaying. The gist of it is that you should look into using DataKeys.

Using a Primary Key with ASP.NET Data Controls

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.