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

Access label control inside RadGrid

2 Answers 261 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sanjay
Top achievements
Rank 1
Sanjay asked on 22 Dec 2010, 04:36 PM
Hello,

I know how to access the controls inside the RadGrid for Grid's Itemdatabound and also the Grid's ItemCommand

I have a ASP repeater in the editformsettings and I am using EditMode="EditForms" in the MasterTableView.

In my edit form template there is a label above the repeater which I need to access and change its text when:
a button inside the Repeater is clicked. So I have the ItemCommand Subroutine in the code behind page which is able to access all the elements of the repeater with no problem but I want to also change the text of the label above the repeater which is a RadGridEditItem after the button is clicked in the repeater.

Can you show me how to?

Thanks,
Sanjay

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Dec 2010, 06:29 AM
Hello Sanjay,

Check out the following code snippet which shows how to access the Label inside EditForm when clicking button inside Repeater.

ASPX:
<FormTemplate>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <br />
    <asp:Repeater ID="rptList" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="rptList_ItemCommand">
        <ItemTemplate>
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </ItemTemplate>
    </asp:Repeater>
</FormTemplate>

C#:
protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
   {
       Repeater reptr = (Repeater)source;
       GridEditFormItem editItem = (GridEditFormItem)reptr.NamingContainer;
       Label lb = (Label)editItem.FindControl("Label1");//accessing Label
       lb.Text = "new text";
   }

Thanks,
Princy.
0
Sanjay
Top achievements
Rank 1
answered on 23 Dec 2010, 02:57 PM
Thanks Princy

Sanjay
Tags
Grid
Asked by
Sanjay
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sanjay
Top achievements
Rank 1
Share this question
or