7 Answers, 1 is accepted
1
Princy
Top achievements
Rank 2
answered on 31 Aug 2010, 12:25 PM
Hello Saba,
Check out the following code snippet which shows how to access controls in CommandItemTemplate from ItemCommand event.
ASPX:
C#:
Thanks,
Princy.
Check out the following code snippet which shows how to access controls in CommandItemTemplate from ItemCommand event.
ASPX:
<
CommandItemTemplate
>
<
asp:LinkButton
ID
=
"LinkButton1"
runat
=
"server"
>LinkButton3</
asp:LinkButton
>
<
asp:LinkButton
ID
=
"LinkButton2"
runat
=
"server"
>LinkButton4</
asp:LinkButton
>
</
CommandItemTemplate
>
C#:
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName ==
"RowClick"
)
{
GridCommandItem cmdItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
LinkButton linkBtn1 = (LinkButton)cmdItem.FindControl(
"LinkButton1"
);
linkBtn1.Visible =
false
;
LinkButton linkBtn2 = (LinkButton)cmdItem.FindControl(
"LinkButton2"
);
linkBtn2.Visible =
false
;
}
}
Thanks,
Princy.
0
Paulo
Top achievements
Rank 1
answered on 18 Mar 2014, 09:34 PM
Princy
I have two buttons in the GridCommandsItem which I would like to make visible or not.
I applied the code you have showed but it does not hide the buttons. If I click on the button it's functionality works but I cannot turn visible to false.
if (e.CommandName == "HideStatus")
{
RadGrid1.MasterTableView.GetColumn("finalstatus").Display = false;
GridCommandItem cmd1 = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
RadButton btn1 = cmd1.FindControl("RadButton2") as RadButton;
btn1.Visible = true;
RadButton btn2 = cmd1.FindControl("RadButton3") as RadButton;
btn2.Visible = false;
RadGrid1.MasterTableView.Rebind();
}
I have two buttons in the GridCommandsItem which I would like to make visible or not.
I applied the code you have showed but it does not hide the buttons. If I click on the button it's functionality works but I cannot turn visible to false.
if (e.CommandName == "HideStatus")
{
RadGrid1.MasterTableView.GetColumn("finalstatus").Display = false;
GridCommandItem cmd1 = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
RadButton btn1 = cmd1.FindControl("RadButton2") as RadButton;
btn1.Visible = true;
RadButton btn2 = cmd1.FindControl("RadButton3") as RadButton;
btn2.Visible = false;
RadGrid1.MasterTableView.Rebind();
}
0
Princy
Top achievements
Rank 2
answered on 19 Mar 2014, 04:18 AM
Hi Paulo,
Please remove the Rebind() from your code for the functionality to work.
C#:
Thanks,
Princy
Please remove the Rebind() from your code for the functionality to work.
C#:
if
(e.CommandName ==
"HideStatus"
)
{
GridCommandItem cmd1 = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
RadButton btn1 = cmd1.FindControl(
"RadButton2"
)
as
RadButton;
btn1.Visible =
true
;
RadButton btn2 = cmd1.FindControl(
"RadButton3"
)
as
RadButton;
btn2.Visible =
false
;
}
Thanks,
Princy
0
Paulo
Top achievements
Rank 1
answered on 20 Mar 2014, 02:19 PM
Hi Princy
I have removed the Rebind() from the code behind and still the functionality to hide the column does work but it does not hide or show the buttons.
This is the front end:
<MasterTableView CommandItemDisplay="Top" CommandItemStyle-Height="30px" >
<CommandItemTemplate>
<table>
<tr>
<td style="padding:1px 1px;">
<telerik:RadButton ID="Button1" AutoPostBack="true" runat="server" CommandName="Rebind" Text="Clear All Filters">
</telerik:RadButton>
</td>
<td style="padding:1px 1px;">
<telerik:RadButton ID="Button2" AutoPostBack="true" runat="server" Visible="true" CommandName="ShowStatus" Text="Show Status Date">
</telerik:RadButton>
</td>
<td style="padding:1px 1px;">
<telerik:RadButton ID="Button3" AutoPostBack="true" runat="server" Visible="false" CommandName="HideStatus" Text="Hide Status Date" >
</telerik:RadButton>
</td>
</tr>
</table>
</CommandItemTemplate>
I have removed the Rebind() from the code behind and still the functionality to hide the column does work but it does not hide or show the buttons.
This is the front end:
<MasterTableView CommandItemDisplay="Top" CommandItemStyle-Height="30px" >
<CommandItemTemplate>
<table>
<tr>
<td style="padding:1px 1px;">
<telerik:RadButton ID="Button1" AutoPostBack="true" runat="server" CommandName="Rebind" Text="Clear All Filters">
</telerik:RadButton>
</td>
<td style="padding:1px 1px;">
<telerik:RadButton ID="Button2" AutoPostBack="true" runat="server" Visible="true" CommandName="ShowStatus" Text="Show Status Date">
</telerik:RadButton>
</td>
<td style="padding:1px 1px;">
<telerik:RadButton ID="Button3" AutoPostBack="true" runat="server" Visible="false" CommandName="HideStatus" Text="Hide Status Date" >
</telerik:RadButton>
</td>
</tr>
</table>
</CommandItemTemplate>
0
Princy
Top achievements
Rank 2
answered on 21 Mar 2014, 04:17 AM
Hi Paulo,
I'm not clear about your requirement. I see that you have set Visible="false", so it wont be shown at first, so I guess you are setting its visibility to true some where else. Here is the code snippet I tried, which works as expected.
ASPX:
C#:
Thanks,
Princy
I'm not clear about your requirement. I see that you have set Visible="false", so it wont be shown at first, so I guess you are setting its visibility to true some where else. Here is the code snippet I tried, which works as expected.
ASPX:
<
CommandItemTemplate
>
<
table
>
<
tr
>
<
td
>
<
telerik:RadButton
ID
=
"Button2"
runat
=
"server"
CommandName
=
"ShowStatus"
Text
=
"Show Status Date"
>
</
telerik:RadButton
>
</
td
>
<
td
>
<
telerik:RadButton
ID
=
"Button3"
runat
=
"server"
CommandName
=
"HideStatus"
Visible
=
"false"
Text
=
"Hide Status Date"
>
</
telerik:RadButton
>
</
td
>
</
tr
>
</
table
>
</
CommandItemTemplate
>
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"HideStatus"
)
{
GridCommandItem cmd1 = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
RadButton btn = cmd1.FindControl(
"Button3"
)
as
RadButton;
btn.Visible =
false
;
}
if
(e.CommandName ==
"ShowStatus"
)
{
GridCommandItem cmd1 = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
RadButton btn = cmd1.FindControl(
"Button3"
)
as
RadButton;
btn.Visible =
true
;
}
}
Thanks,
Princy
0
Paulo
Top achievements
Rank 1
answered on 24 Mar 2014, 02:53 PM
Princy
I have copied and paste your code (which is similar to mine) into my project and still does not work. In my project I have two buttons one hides column A and the other button shows it. At first the button to hide the column A would be not seen by the user and as soon as the user click on "Show Column A" the button "Show Column A" would set its visibility to false and would set the "Hide Column A" to visible. The functionality to show and hide the column works fine, but the visibility of the button does not.
Thanks
I have copied and paste your code (which is similar to mine) into my project and still does not work. In my project I have two buttons one hides column A and the other button shows it. At first the button to hide the column A would be not seen by the user and as soon as the user click on "Show Column A" the button "Show Column A" would set its visibility to false and would set the "Hide Column A" to visible. The functionality to show and hide the column works fine, but the visibility of the button does not.
Thanks
0
Hi Paulo,
I prepared a small sample which demonstrates the same scenario as the one which you have described. Please give it a try and let me know about the result.
Regards,
Kostadin
Telerik
I prepared a small sample which demonstrates the same scenario as the one which you have described. Please give it a try and let me know about the result.
Regards,
Kostadin
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.