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

selected row and FindControl with grid

3 Answers 532 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anjali
Top achievements
Rank 1
Anjali asked on 20 Apr 2011, 10:24 PM

Hello Everyone,
I am binding the Grid inside a loadHeader method and inside that method, I need to call an event called raIseChangedEvent. Inside raiseChangedEvenet, I need to find the label control inside the gridview and get the value of it. I am not sure how to do this. I did this long time ago  using asp grid, but here with radGrid, I don't know how to do this. below is my code

public loadHeader()
{

    RadGrid_Header.DataSource = HeaderList;
         RadGrid_Header.DataBind();
         RaiseChangedEvent();

}

 

    protected void RaiseChangedEvent()
    {
       // This is what i did with asp.net gridview
         grd_view_tracking.SelectedIndex = 0;
        GridViewRow selected_row = grd_view_tracking.SelectedRow;
        string job_seq_text_val = ((Label)selected_row.FindControl("lbl_job_seq")).Text;

      

    }

How can I get the value of job_seq_text_val  in RadGrid.

Any help will be greatly appreciated

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Apr 2011, 06:19 AM
Hello Nitu,

You can access the selected row items as shown below.
C#:
foreach(GridDataItem item in RadGrid1.SelectedItems)//loops through selected row
   {
      Label lbl=(Label) item.FindControl("Label1");
   }

Also take a look at the following documentation.
Accessing cells and rows

Thanks,
Shinu.
0
Anjali
Top achievements
Rank 1
answered on 22 Apr 2011, 07:36 PM
Thanks for your reply, thats what I needed, but somehow when I am debugging my program, i am not going inside the loop. below is my code

 

 

foreach (GridDataItem item in RadGrid_RepHeader.SelectedItems)

 

 

{

 

    RepId = ((

 

Label)item.FindControl("lbl_Rep_Id")).Text;

 

 

}

and this is the label inside the radGrid.

 

 

 

 

 

<asp:Label ID="lbl_Rep_Id" runat="server" Visible="true" Text='<%#Bind("repId") %>'></asp:Label>

Any help will be greatly appreciated.

 

0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Apr 2011, 08:38 AM
Hello Nitu,

When you are selecting row from client side, it won't persist after PostBack. You can  try the following approach to persist the selected row, which is selected from client side. Please review the following help article.
Persisting the selected rows client-side on sorting/paging/filtering/grouping.

Another approach is selecting the row from server side, add GridButtonColumn columns to a grid to handle the selection and deselection. This  can be done by setting the CommandName property of the GridButtonColumn.
Selecting a row with a select button (server-side)

Thanks,
Princy.
Tags
Grid
Asked by
Anjali
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Anjali
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or