Hi,
In my web application, I am trying to integrate RadGrid from code behind and depending on the GridBoundColumn DataField “Status” (having value 1 and 0), I would like to show/hide “Deactivate”/”Activate” image command button written under ItemTemplate, After lot of Googling, I couldn’t find similar solution. If there is any way out to achieve this, please suggest.
My code is as followes,
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="True" AllowPaging="True" AllowSorting="True" AllowAutomaticDeletes="True" OnItemCommand="RadGrid1_ItemCommand">
<MasterTableView EditMode="PopUp" PageSize="20" AutoGenerateColumns="False" DataKeyNames="Consequence_Id" ClientDataKeyNames="Consequence_Id">
<PagerStyle Mode="NextPrevAndNumeric" />
<Columns>
<telerik:GridBoundColumn DataField="Module_Content_Text"
HeaderText="Consequence_Name" SortExpression="Module_Content_Text"
UniqueName="Module_Content_Text">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Status" Visible="false"
UniqueName="Status">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
<HeaderTemplate>
<table width="100%">
<tr>
<td>
Options</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table width="100%">
<tr>
<td>
<asp:ImageButton ID="ImgBtnDeactivate" ToolTip="Deactivate Record" runat="server" CausesValidation="False" CommandName="Deselect" OnClientClick="return confirm('Are you sure you want to Deactivate this record?');" ImageUrl="~/Images/icon/cross.gif" />
</td>
<td>
<asp:ImageButton ID="ImgBtnActivate" ToolTip="Activate Record" runat="server" CausesValidation="False" CommandName="Select" OnClientClick="return confirm('Are you sure you want to Activate this record?');" ImageUrl="~/Images/icon/right.gif" />
</td>
<td>
<asp:ImageButton ID="ImgBtnDelete" ToolTip="Delete Record" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this record?');" ImageUrl="~/Images/icon/delete.gif" />
</td>
<td>
<asp:ImageButton ID="ImgBtnEdit" ToolTip="Edit Record" runat="server" CausesValidation="False" CommandName="Edit" OnClientClick="return confirm('Are you sure you want to Edit this record?');" ImageUrl="~/Images/icon/edit.gif" />
</td>
</tr>
</table>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
------------------------------------------------
private void displayConsequenceGrid()
{
MiddleWare.BL.Consequence objC = new MiddleWare.BL.Consequence();
DataTable dt = new DataTable();
objC._Company_Id = System.Convert.ToInt32(Session[CSession.__Session_Company_Id]);
objC._Language_Id = System.Convert.ToInt32(Session[CSession.__Session_Lanuage_Id]);
dt = objC.GetDataAllConsequence();
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
}
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
int retResult = -100;
MiddleWare.BL.Consequence oConsq = new MiddleWare.BL.Consequence();
oConsq._Updated_By = Convert.ToInt32(Session[CSession.__Session_User_Id]);
oConsq._Module_Id = oConsq._Module_Id;
if (e.CommandName == RadGrid.EditCommandName)
{
int Consequence_Id = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Consequence_Id"].ToString());
}
else if (e.CommandName == RadGrid.DeleteCommandName)
{
oConsq._Consequence_Id = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Consequence_Id"].ToString());
retResult = oConsq.DeleteConsequence();
if (retResult == 2)
{
displayConsequenceGrid();
}
}
else if (e.CommandName == RadGrid.SelectCommandName)
{
oConsq._Consequence_Id = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Consequence_Id"].ToString());
retResult = oConsq.ActivateConsequence();
if (retResult == 1)
{
displayConsequenceGrid();
}
}
I am attaching the required result page as attached picture. Please help me out.
.reToolbar.Vista
.tbiEntity {
background-image: url(/images/rgb.png);
}

| switch (rbl.SelectedValue) |
| { |
| case "Full": |
| radTreeView.CheckAllNodes(); |
| return; |
| case "None": |
| isChecked = false; |
| break; |
| case "Partial": |
| isChecked = false; |
| break; |
| default: |
| break; |
| } |
| foreach (RadTreeNode node in radTreeView.Nodes) |
| { |
| node.Checked = isChecked; |
| } |

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource =
this.GridSource2;
}
private object GridSource2
{
get
{
Object obj = this.ViewState["_gds"];
if (obj != null)
{
return obj;
}
else
{
string s;
object ss = from i in EntityConnection.INVENTORY select new { i.INV_DEVICENAME, i.INV_DEVICETYPE };
this.ViewState["_gds"] = ss;
return ss;
}
}
}
| protected void CandidateListGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| RadComboBox lastNameInput = (RadComboBox)FilterData.FindControl("LastNameInput"); |
| RadComboBox firstNameInput = (RadComboBox)FilterData.FindControl("FirstNameInput"); |
| RadDatePicker dateLastContractFromInput = (RadDatePicker)FilterData.FindControl("DateLastContractFromInput"); |
| RadDatePicker dateLastContractUntilInput = (RadDatePicker)FilterData.FindControl("DateLastContractUntilInput"); |
| RadComboBox StatusComboBox = (RadComboBox)FilterData.FindControl("StatusComboBox"); |
| var statusItems = from itm in StatusComboBox.Items |
| where ((CheckBox)itm.FindControl("CheckBox")).Checked |
| select itm.Value; |
| CandidateListGrid.DataSource = this.presenter.ListCandidates( |
| ((lastNameInput != null) ? lastNameInput.Text : "") |
| , ((firstNameInput != null) ? firstNameInput.Text : "") |
| , statusItems |
| , ((dateLastContractFromInput != null) ? dateLastContractFromInput.SelectedDate : DateTime.MinValue) |
| , ((dateLastContractUntilInput != null) ? dateLastContractUntilInput.SelectedDate : DateTime.MinValue) |
| ); |
| } |
| <telerik:RadGrid ID="CandidateListGrid" runat="server" AllowPaging="True" AllowSorting="true" GridLines="None" |
| AutoGenerateColumns="False" PageSize="10" |
| AllowMultiRowSelection="True" EnableEmbeddedSkins="False" Skin="USGFOEXTelerik" |
| OnNeedDataSource="CandidateListGrid_NeedDataSource" > |
| <MasterTableView ClientDataKeyNames="ID"> |
| <Columns> |
| <telerik:GridBoundColumn DataField="LastName" HeaderText="Naam" SortExpression="LastName" |
| UniqueName="LastName"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="FirstName" HeaderText="Voornaam" SortExpression="FirstName" |
| UniqueName="FirstName"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="ContractState" HeaderText="Status" SortExpression="ContractState" |
| UniqueName="ContractState"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="LastContractDate" DataType="System.DateTime" |
| HeaderText="Laatste contract" SortExpression="LastContractDate" UniqueName="LastContractDate"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| public class Candidate |
| { |
| public int Id { get; set; } |
| public string FirstName { get; set; } |
| public string LastName { get; set; } |
| public DateTime LastContractDate { get; set; } |
| public string ContractState { get; set; } |
| } |