umit celik
Top achievements
Rank 1
umit celik
asked on 22 Nov 2009, 01:05 PM
Hello,
I want to show commnad button in a grid accroding to object's Active boolean field. When it is true, it should show "Deactivate" text, when it is false "Activate" text. What is the best practice to do this behaviour with radgrid.
Thank you.
I want to show commnad button in a grid accroding to object's Active boolean field. When it is true, it should show "Deactivate" text, when it is false "Activate" text. What is the best practice to do this behaviour with radgrid.
Thank you.
4 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 23 Nov 2009, 05:07 AM
Hi Umit Celik,
Try the following approach for setting the text according to boolean field value.
ASPX:
-Shinu.
Try the following approach for setting the text according to boolean field value.
ASPX:
| <Columns> |
| <telerik:GridTemplateColumn> |
| <ItemTemplate> |
| <asp:Button ID="Button1" runat="server" Text='<%# Convert.ToBoolean(Eval("BoolStatus")) == true ? "Deactivate" : "Activate" %>' /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| . . . |
| </Columns> |
-Shinu.
0
umit celik
Top achievements
Rank 1
answered on 23 Nov 2009, 08:13 PM
thanks for your answer.
how can i do the same thing in code?
how can i do the same thing in code?
0
Accepted
Casey
Top achievements
Rank 1
answered on 23 Nov 2009, 09:03 PM
Hi Umit,
I think you can achieve this functionality by using the following code in the RadGrid ItemDataBound event. Replace "BUTTON" and "BOOLEAN" with your appropriate column Unique Names.
Hope this helps.
Casey
I think you can achieve this functionality by using the following code in the RadGrid ItemDataBound event. Replace "BUTTON" and "BOOLEAN" with your appropriate column Unique Names.
Hope this helps.
Casey
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| foreach (GridDataItem itm in RadGrid1.Items) |
| { |
| Button btn = itm["BUTTON"].Controls[1] as Button; |
| if (itm["BOOLEAN"].Text == "0") |
| { |
| btn.Text = "Deactivate"; |
| } |
| else if (itm["BOOLEAN"].Text == "1") |
| { |
| btn.Text = "Activate"; |
| } |
| } |
| } |
| <telerik:GridTemplateColumn UniqueName="BUTTON"> |
| <ItemTemplate> |
| <asp:Button ID="Button1" runat="server" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> <
telerik:GridBoundColumn UniqueName="BOOLEAN" Visible="false"/> <telerik:GridBoundColumn |
0
umit celik
Top achievements
Rank 1
answered on 23 Nov 2009, 10:22 PM
very thanks.