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

pager template

1 Answer 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ajmal
Top achievements
Rank 1
ajmal asked on 21 Jul 2010, 09:48 AM
Hello,

I have a button at my pager template in GRID with text = "Approve", on page load i want text change on button clicking, means if text = "approve" is clicked then text should change to  = "raject" and if text = "reject" is clciked, the  text must  = "approve"

.......

 

<PagerTemplate>

 

 

<table>

 

 

<tr>

 

 

<td>

 

 

<asp:Button ID="btn1" runat="server" Text="Approve" />

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

 

</PagerTemplate>

 


 

</telerik:RadGrid>

I m trying to do below manner, but won't able to capture button click event, please help

 

 

 

 

protected

 

void grdADInbox_ItemCreated(object sender, GridItemEventArgs e)

 

{

 

if (e.Item is GridPagerItem)

 

{

 

GridPagerItem item = (GridPagerItem) e.Item;

 

 

Button btn = item.FindControl("btnFutureApprovals") as Button;

 

 

switch (btnFutureApprovals.Text)

 

{

 

case "Future Approvals":

 

btnFutureApprovals.Text =

"Current Approvals";

 

 

break;

 

 

case "Current Approvals":

 

btnFutureApprovals.Text =

"Future Approvals";

 

 

break;

 

}

}

}

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Jul 2010, 10:53 AM
Hello Ajmal,

There are two option to achieve this. One is you can directly attach an 'onClick' event to the Button in PagerTemplate. And in the event handler change the Button Text.

ASPX:
<PagerTemplate>
    <asp:Button ID="btn1" runat="server" Text="Approve" CommandName="buttonClick" />
</PagerTemplate>

C#:
protected void btn1_Click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        if (btn.Text == "Approve")
             btn.Text = "Reject";
        else
            btn.Text = "Approve";
    }

The second option is adding one CommandName to the Button and in ItemCommand event, change the Button Text accordingly.

ASPX:
<PagerTemplate>
    <table>
        <tr>
            <td>
              <asp:Button ID="btn1" runat="server" Text="Approve" CommandName="buttonClick" />
            </td>
        </tr>
    </table>
</PagerTemplate>

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
       if (e.CommandName == "buttonClick")
       {
           GridPagerItem pagerItem = (GridPagerItem)e.Item;
           Button btn = (Button)pagerItem.FindControl("btn1");
           if (btn.Text == "Approve")
               btn.Text = "Reject";
           else
               btn.Text = "Approve";
       }
    }

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