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

Hide RadGridDropDown Column in Edit Mode

4 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bahram
Top achievements
Rank 2
Bahram asked on 25 Jul 2011, 04:14 PM
Hello everybody,
I have seen many posts and comments about this but none do works,
I have a RadGrid with a GridDropDownColumn, I tend to make it invisible in Edit Mode(when I click Edit Button of selected row) under specific Condition in Code Behind.It is not in Inplace Mode.Here Is My Source Code :
I want to hide "SiteOwnerId" under Specific Condition.
<telerik:RadGrid ID="RadGridUserInfo" CssClass="myRadGrid" GridLines="None" runat="server"
  
AllowAutomaticDeletes="True" PageSize="12" AllowPaging="True" AutoGenerateColumns="False"
  
OnItemUpdated="RadGridUserInfo_ItemUpdated" OnItemDeleted="RadGridUserInfo_ItemDeleted"
  
OnItemInserted="RadGridUserInfo_ItemInserted" OnDataBound="RadGridUserInfo_DataBound"
  
AllowFilteringByColumn="True" OnItemCreated="RadGridUserInfo_ItemCreated" OnInsertCommand="RadGridUserInfo_InsertCommand"
  
OnUpdateCommand="RadGridUserInfo_UpdateCommand" OnNeedDataSource="RadGridUserInfo_NeedDataSource"
  
OnEditCommand="RadGridUserInfo_EditCommand" OnItemDataBound="RadGridUserInfo_ItemDataBound"
  
OnDeleteCommand="RadGridUserInfo_DeleteCommand" 
  
oncolumncreated="RadGridUserInfo_ColumnCreated">
  
<SelectedItemStyle Font-Names="Tahoma" Font-Size="11px" ForeColor="#8abe23" />
  
<MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="UserInfoId"
  
HorizontalAlign="NotSet" AutoGenerateColumns="False" Font-Names="Tahoma" EditFormSettings-FormStyle-ForeColor="Black"
  
Font-Size="11px">
  
<CommandItemTemplate>
  
<div style="padding: 5px 5px;" dir="rtl">
  
asp:LinkButton ID="LinkButton4" runat="server" Font-Names="Tahoma" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../Images/Icons/Refresh.gif" />به روزآوري اطلاعات</asp:LinkButton>
  
</div>
  
</CommandItemTemplate>
  
<Columns>
  
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
  
<ItemStyle CssClass="MyImageButton" />
  
</telerik:GridEditCommandColumn>
  
<telerik:GridButtonColumn ConfirmText="آيا از حذف ركورد جاري مطمئنيد؟" ConfirmDialogType="RadWindow"
  
ConfirmTitle="حذف ركورد جاري" ButtonType="ImageButton" CommandName="Delete" Text="حذف"
  
UniqueName="DeleteColumn">
  
<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
  
</telerik:GridButtonColumn>
  
<telerik:GridDropDownColumn DataField="SiteOwnerId" EditFormColumnIndex="1" HeaderText="شركت فروشنده پنل"
  
UniqueName="SiteOwnerId" ListTextField="SiteOwnerName" ListValueField="SiteOwnerId"
  
DataSourceID="sds_SiteOwner" ColumnEditorID="GridDropDownEditor">
  
</telerik:GridDropDownColumn>
  
</Columns>
  
<EditFormSettings ColumnNumber="3" CaptionDataField="UserInfoId" CaptionFormatString="ويرايش اطلاعات"
  
InsertCaption="">
  
<EditColumn ButtonType="ImageButton" InsertText="ثبت پنل" UpdateText="ويرايش پنل"
  
UniqueName="EditCommandColumn1" CancelText="لغو ويرايش">
  
</EditColumn>
  
</EditFormSettings>
  
</MasterTableView>
  
</telerik:RadGrid>

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jul 2011, 04:49 AM
Hello Bahram,

GridDropDownColumn is rendered as DropDownList in edit mode. Try the following code snippet to hide the dropdowncolumn in edit mode.
aspx:
<telerik:GridDropDownColumn DataField="SiteOwnerId" EditFormColumnIndex="1" HeaderText="شركت فروشنده پنل"
  UniqueName="SiteOwnerId" ListTextField="SiteOwnerName" ListValueField="SiteOwnerId"
  DataSourceID="sds_SiteOwner" ColumnEditorID="GridDropDownEditor" DropDownControlType="DropDownList">
</telerik:GridDropDownColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
       if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            DropDownList drList = (DropDownList)item["SiteOwnerId"].Controls[0];
            drList.Visible = false;
        }
}

Thanks,
Princy.
0
Bahram
Top achievements
Rank 2
answered on 26 Jul 2011, 05:45 AM
Hi Princy,
It is perfect,thank you So much.
0
Bahram
Top achievements
Rank 2
answered on 26 Jul 2011, 06:09 AM
Hi Princy,
There is still a problem.The HeaderText of DropDown is still on the page and I didnt found a property like this to make it invisible.

DropDownList

 

 

drList = (DropDownList)editedItem["SiteOwnerId"].Controls[0];

 

drList.HeaderText = ...
or something like this.

 
0
Princy
Top achievements
Rank 2
answered on 26 Jul 2011, 11:05 AM
Hello Bahram,

Try the following code snippet in PreRender event to hide the header text.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
 RadGrid1.MasterTableView.GetColumn("SiteOwnerId").HeaderText = "";
}

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