This is a migrated thread and some comments may be shown as answers.

How to fetch the grid row data on button click

4 Answers 358 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Akki
Top achievements
Rank 1
Akki asked on 01 Mar 2012, 07:35 AM
Hi All,

I have button inside the rad grid control. I want to fetch the particular grid row data (ex. hidden field value) on button click. For this I wrote code like this...

    protected void btnOne_OnClick(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        GridDataItem item = (GridDataItem)btn.NamingContainer;    
        HiddenField hdn = (HiddenField)item.FindControl("hdnOne");
    }

It is working, but some time it shows the value is repeating (i.e. showing some other value for hidden field). Is there any other way, to do this..
Thanks in advance.
Akki

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Mar 2012, 07:50 AM
Hello,

I cannot reproduce the issue at my end. Here is the sample code that I tried which worked as expected.
C#:
protected void Button1_Click(object sender, EventArgs e)
{
 foreach (GridDataItem itm in grid.MasterTableView.Items)
 {
  HiddenField hidn = (HiddenField)itm.FindControl("HiddenField1");
  string value = hidn.Value;
 }
}

Thanks,
Princy.
0
Princy
Top achievements
Rank 2
answered on 01 Mar 2012, 07:50 AM
.

0
Akki
Top achievements
Rank 1
answered on 01 Mar 2012, 08:04 AM
Thanks Princy,

Is there any other way without for loop. The grid contains button and hidden field in each row, I want that hidden filed value on button click.

Thanks,
Akki
0
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Mar 2012, 10:55 AM
Hello,

The code which was given by you is perfectly working from my side.
Can you please send error sereenshot or code so we can identify the issue?

If possible then you can also use DataKey to store the values.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Akki
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Akki
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or