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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:14:13+00:00 2026-05-23T15:14:13+00:00

I thought this would be an easy one for me to figure out (or

  • 0

I thought this would be an easy one for me to figure out (or atl east find someone online who has) but I am running into issues.

I have the following code that creates my gridview:

    <asp:GridView runat="server" ID="ContactsGrid" AutoGenerateColumns="False" DataSourceID="LinqContact"
            CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="ContactsGridView_RowDeleting" >
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:BoundField DataField="IConact_ID" Visible="false" ReadOnly="true" />
        <asp:BoundField DataField="cFirstName" HeaderText="First Name" ReadOnly="True" />
        <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
    </Columns>
</asp:GridView>

<asp:LinqDataSource ID="LinqContact" runat="server" ContextTypeName="TIPS.App_Data.TIPSDataContext" onselecting="LinqContact_Selecting" >
</asp:LinqDataSource>

Now on the c# side, I want to be able to pull the value from the first column (which is hidden) and use it to delete that specific record (with the onroedeleting event), but all the ways I found to pull the value, all come up null, like what would happen if I didn’t have a LinqDatasource.

I have tried (and a slew of other that really didn’t seem to be right, so not listed):

ContactsGrid.SelectedRow.Cells[0].Text;
ContactsGrid.Columns[0];

Thanks for any help!

Edit:

Ok, so I found that you can’t get the value of a column this is hidden when you hide it using the grid. I did find a work around. If you hide the column using css instead, you can still access the colum.

<style type="text/css">
.hiddencol
{
    display:none;
}

</style>

<asp:BoundField DataField="IContact_ID"  ReadOnly="true" itemstyle-cssclass="hiddencol" />

I don’t think that this is the prefered .net way. I found a reference to something called datakeynames which seems to be the proper way. I am going to dig into those next.

Edit #2:

I see that Maras and myself both came up with a solution for the hidden field, but I think I found the best one (cause its simple and built in).

In the gridview tag you can set the datakeynames attribute to your column (like a primary key, which is what I was storing in my hidden column) you can also store multiple columns.

    <asp:GridView runat="server" ID="ContactsGrid" AutoGenerateColumns="False" DataSourceID="LinqContact" DataKeyNames="IContact_ID"
CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="ContactsGridView_RowDeleting" >

you can then reference it with:

ContactsGrid.DataKeys[e.RowIndex].Value;
  • 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-05-23T15:14:14+00:00Added an answer on May 23, 2026 at 3:14 pm

    Try this:

    void ContactsGrid_RowDeleting(Object sender, GridViewDeleteEventArgs e)
    {
        ContactsGrid.Rows[e.RowIndex].Cells[0];
    }
    

    See here for more details http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdeleting.aspx#Y200

    .

    Edit after author’s comment:

    If you set it visibility to ‘false’ then there is nothing your browser can send you back in postback. You can use hidden field like in the second example:

    <asp:GridView runat="server" ID="gv" OnRowDeleting="gv_RowDeleting" AutoGenerateColumns="false" AutoGenerateDeleteButton="true">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:HiddenField ID="hf" runat="server" Value="<%# ((YourItemType)Container.DataItem).Id %>" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    
    
    protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        HiddenField hf = (HiddenField) gv.Rows[e.RowIndex].Cells[0].FindControl("hf");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this would be fairly easy, but I'm totally baffled. I want one
I thought this one would be easy, but after an hour of googling, i
I would have thought this would be an easy one to Google, but I've
I thought this would have been an easy thing to find but I've failed.
I thought this would be pretty easy but I'm running into all sorts of
I would have thought that this would be an easy thing to do, but
I thought this would be fairly simple but it turns out not to work
I thought this would be easy, but after scanning many pages Google hasn't come
I thought this would be easy. The Google makes me think otherwise. What I
I thought this would be very easy. I downloaded the JDK, extracted src.zip, modified

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.