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

Dynamically change Button text inside GridTemplateColumn in radgrid

3 Answers 737 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Akki
Top achievements
Rank 1
Akki asked on 19 Feb 2012, 01:39 PM
Hi,
I am using radstrip and radgrid. Inside radstrip there are 3 tabs, on click of each tab i will be displaying data using radgrid.
radgrid contains GridTemplateColumn where i have placed 2 asp : button, for the first tab i will assign default text with respect to data
displayed on click of first tab. On click of second tab. i want to change the text of that button inside GridTemplateColumn as data in grid
changes with respect 2 tab.. How can i accomplish this ?? Help me out ?

code is as below.


<telerik:RadTabStrip ID="rdStrip" runat="server" SelectedIndex="0"
     OnTabClick="rdStrip_TabClick" Skin="Outlook" Width="100%" Height="27px">
            <Tabs>
                <telerik:RadTab Text="abc" Selected="true" Width="150Px"></telerik:RadTab>
                <telerik:RadTab Text="def" Width="150Px"></telerik:RadTab>
                <telerik:RadTab Text="ghi" Width="150Px"></telerik:RadTab>
            </Tabs>
        </telerik:RadTabStrip>

  <telerik:RadGrid ID="rdgrd" runat="server" AllowPaging="true"
            AutoGenerateColumns="false" PageSize="20" GridLines="None"
            CssClass="radgrid" AllowFilteringByColumn="true" Width="100%"
            Skin="Office2007">
            <ExportSettings ExportOnlyData ="true" HideStructureColumns ="false"></ExportSettings>
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView AllowPaging="true" AllowFilteringByColumn="true"
                CommandItemDisplay="Top">
                <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"/>
                <CommandItemSettings ExportToExcelText="Export To Excel" ShowExportToExcelButton="true"
                    ShowAddNewRecordButton="false" ShowRefreshButton="false" />
                <Columns>
                    <telerik:GridBoundColumn HeaderText="SchoolLevel" DataField="schooldsc" UniqueName="SchoolLevelDesc">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="School" DataField="schooldscd" UniqueName="School">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn Visible="true">
                    <ItemTemplate>
                    <asp:Button ID="btnFirst" runat="server" Text="Cancel" OnClick="btnFirstOnClick" />
                    </ItemTemplate>
                    </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn Visible="true">
                    <ItemTemplate>
                    <asp:Button ID="btnSecond" runat="server" Text="Insert" OnClick="btnSecondOnClick" />
                    </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings AllowColumnsReorder="true" ReorderColumnsOnClient="true">
                <Resizing EnableRealTimeResize="true"  />
            </ClientSettings>
        </telerik:RadGrid>

Regards,
Akki

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 22 Feb 2012, 08:47 AM
Hello Akki,

Try the following code in the TabClick event handler:

protected void rdStrip_TabClick(object sender, RadTabStripEventArgs e)
{
    foreach (GridDataItem item in rdgrd.MasterTableView.Items)
    {
        ((Button)item.FindControl("btnFirst")).Text = "Text for button first";
        ((Button)item.FindControl("btnSecond")).Text = "Text for button second";
    }
}

Veli
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Edgar
Top achievements
Rank 1
answered on 28 Feb 2012, 11:08 PM
How can we set the text in the Button control, calling a javascript function?
protected void rdStrip_TabClick(object sender, RadTabStripEventArgs e)
{
    foreach (GridDataItem item in rdgrd.MasterTableView.Items)
    {
        ((Button)item.FindControl("btnFirst")).Text = RETURNED_VALUE_IN_JAVASCRIPT_CODE;
        
0
Veli
Telerik team
answered on 29 Feb 2012, 01:53 PM
@Edgar,

You can set a specific CSS class to all buttons in a particular column. You can then find all buttons with that CSS class when the DOM loads and set their respective value.

Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Akki
Top achievements
Rank 1
Answers by
Veli
Telerik team
Edgar
Top achievements
Rank 1
Share this question
or