Hello, I'm using a RadGrid to display some data, and I want to be able to show or hide one of the cells based on the value of another cell on a particular row. In this particular instance, I want to hide the "Accept" and "Reject" cells based on what the text in "Status" is for that particular row. So if the "Status" field comes out to = "Accepted", i want the Accept and Reject cells to show. but if it says "Rejected" I don't want those button cells to show up. How can I do this?
<tel:RadGrid ID="rgReferrals" runat="server" DataSourceID="odsReferrals" EnableLinqExpressions="true" AllowFilteringByColumn="true" AllowPaging="true" AllowSorting="true" AutoGenerateHierarchy="true" OnDetailTableDataBind="rgReferrals_DetailTableDataBind" OnPreRender="rgReferrals_PreRender" > <MasterTableView AutoGenerateColumns="false"> <Columns> <tel:GridBoundColumn HeaderText="ID" DataField="ReferralID" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" /> <tel:GridBoundColumn HeaderText="Status" DataField="Status" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" /> <tel:GridButtonColumn HeaderText="Accept" ImageUrl="~/Content/Images/Icons/tick.png" CommandName="Accept" ButtonCssClass="InoperatableButton" ButtonType="ImageButton" Text="Accept" /> <tel:GridButtonColumn HeaderText="Reject" ImageUrl="~/Content/Images/Icons/cross.png" CommandName="Reject" ButtonCssClass="InoperatableButton" ButtonType="ImageButton" Text="Reject" />6 Answers, 1 is accepted
0
Accepted
Mike Nogen
Top achievements
Rank 1
answered on 06 Jan 2011, 09:35 PM
Hello!
I think that this should be the same. I have an function where I enable or disable a button based on another cell value.
To check this use the RadGrid1_ItemDataBound event to check your cell and to show/hide another cell.
/M
I think that this should be the same. I have an function where I enable or disable a button based on another cell value.
<telerik:GridButtonColumn FooterText="" DataTextFormatString="Go to booking" ButtonType="PushButton" UniqueName="GoToBooking" HeaderText="Go to booking" CommandName="GoToBooking" DataTextField="CustomerID"> </telerik:GridButtonColumn>To check this use the RadGrid1_ItemDataBound event to check your cell and to show/hide another cell.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { //when the Grid is in normal mode if (e.Item is GridDataItem) { GridDataItem item = e.Item as GridDataItem; if (!string.IsNullOrEmpty(item["ReCurrence"].Text.Replace(" ","").Trim())) { //GoToBooking item["GoToBooking"].Enabled = false; item["GoToBooking"].ToolTip = "This is a ReCurrence time and is not supported in this function"; } } }/M
0
Devon
Top achievements
Rank 1
answered on 07 Jan 2011, 08:19 PM
This worked very well! But I have another problem- I'm also using a details view on this page, and it errors when it looks for item["status"] when loading the details view, because that column doesn't exist in the details. Is there a way to check to see if item["status"] exists so I can make it skip the code pertaining to it? Right now i just put a try-catch(GridException) around it,which works, but Id prefer to be able to check with an if statement. How can I do this?
0
Mike Nogen
Top achievements
Rank 1
answered on 07 Jan 2011, 08:51 PM
Could you show your whole grid declaration (please use the code function when you insert the code). And also insert the code snippet/event where you get the error and I will take a look.
/M
/M
0
Devon
Top achievements
Rank 1
answered on 07 Jan 2011, 09:28 PM
<tel:RadGrid ID="rgReferrals" runat="server" DataSourceID="odsReferrals" EnableLinqExpressions="true" AllowFilteringByColumn="true" AllowPaging="true" AllowSorting="true" AutoGenerateHierarchy="true" OnDetailTableDataBind="rgReferrals_DetailTableDataBind" OnItemDataBound="rgReferrals_ItemDataBound"> <MasterTableView AutoGenerateColumns="false"> <Columns> <tel:GridBoundColumn HeaderText="ID" DataField="ReferralID" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" /> <tel:GridBoundColumn HeaderText="Client" DataField="ClientName" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true"/> <tel:GridBoundColumn HeaderText="" DataField="ClientGender" AllowFiltering="false"/> <tel:GridBoundColumn HeaderText="Insurance" DataField="ClientInsurance" AllowFiltering="false"/> <tel:GridBoundColumn HeaderText="Referral Source" DataField="ReferralAgencyName" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" /> <tel:GridBoundColumn HeaderText="Referred Date" DataField="ReferralDate" DataType="System.DateTime" FilterListOptions="VaryByDataType" /> <tel:GridBoundColumn HeaderText="Referral Owner" DataField="ReferralIndividualName" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" /> <tel:GridBoundColumn HeaderText="Status" DataField="Status" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" /> <tel:GridBoundColumn HeaderText="Zip" DataField="ReferralZip" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" /> <tel:GridBoundColumn HeaderText="Language" DataField="ReferralLanguage" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" /> <tel:GridButtonColumn HeaderText="Accept" ImageUrl="~/Content/Images/Icons/tick.png" UniqueName="Accept" CommandName="Accept" ButtonCssClass="InoperatableButton" ButtonType="ImageButton" Text="Accept" /> <tel:GridButtonColumn HeaderText="Reject" ImageUrl="~/Content/Images/Icons/cross.png" UniqueName="Reject" CommandName="Reject" ButtonCssClass="InoperatableButton" ButtonType="ImageButton" Text="Reject" /> </Columns> <DetailTables> <tel:GridTableView Name="Suggestions" AutoGenerateColumns="false" Width="100%" > <Columns> <tel:GridBoundColumn HeaderText="Suggested Caseworker" DataField="SuggestedCaseworker" ItemStyle-Width="40%"/> <tel:GridBoundColumn HeaderText="Zip Code" DataField="SugZip" ItemStyle-Width="20%"/> <tel:GridBoundColumn HeaderText="Language" DataField="SugLanguage" ItemStyle-Width="20%"/> <tel:GridButtonColumn HeaderText="Assign" ImageUrl="~/Content/Images/Icons/tick.png" CommandName="Assign" ButtonCssClass="InoperatableButton" ButtonType="ImageButton" ItemStyle-Width="20%"/> </Columns> <NoRecordsTemplate> This referral has not yet been accepted and cannot be assigned. </NoRecordsTemplate> </tel:GridTableView> </DetailTables> </MasterTableView> <ClientSettings EnablePostBackOnRowClick="false"> <Selecting AllowRowSelect="true" /> <ClientEvents OnRowSelected="Hb.Referrals.List.RowSelected" /> </ClientSettings> </tel:RadGrid>C#
protected void rgReferrals_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = e.Item as GridDataItem; try { // this next line gives the error
if (!item["Status"].Text.Equals("Accept Pending")) { item["Accept"].Controls[0].Visible = false; item["Reject"].Controls[0].Visible = false; } else { item["ExpandColumn"].Controls[0].Visible = false; } } catch (GridException ex) { } } }0
Mike Nogen
Top achievements
Rank 1
answered on 08 Jan 2011, 03:32 PM
What happens if you do it like this
Check if the Item is expanded or not. And only check the status item at this point.
/M
if (e.Item is GridDataItem && !e.Item.Expanded) {Check if the Item is expanded or not. And only check the status item at this point.
/M
0
Devon
Top achievements
Rank 1
answered on 10 Jan 2011, 02:25 PM
Worked great! Thanks for all your help!