Click here to Skip to main content
13,762,463 members
Rate this:
Please Sign up or sign in to vote.
See more:
i have button in gridview and on clicking on that a new row is created i took the ID in a hidden field in the grid view and then want to save the record of new created row.So how can i get the hidden field Value from that grid

What I have tried:

if (Hdid.Value == String.Empty)
      Hdid.Value = "0";

   Hdid.Value = (Convert.ToInt32(Hdid.Value) + 1).ToString();

                        Label1.Text = Hdid.Value;
Posted 1-Jan-18 0:08am
Updated 2-Jan-18 21:34pm
Maciej Los 2-Jan-18 7:37am
And what's wrong woith your code?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

At Button Click event, you can cast the sender of the object to get the current row and then find the HiddenField control. For example:

protected void Button1_Click(object sender, EventArgs e) {
            Button b = (Button)sender;
            GridViewRow row = (GridViewRow)b.NamingContainer;
            string field1 = ((HiddenField)row.FindControl("YourHiddenControlID")).Value;   

If you are working with dynamic row generation using GridView then this article should help you get started: Dynamically Adding and Deleting Rows in GridView and Saving All Rows at Once[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181111.1 | Last Updated 3 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100