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

Grid hide column sutaible event

5 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 10 Dec 2013, 09:21 AM
Hi,
i am having grid in which i am doing delete ,
for first record delete its working fine but for second time it is not getting the id of hide column,
so where do i hide column
my code is
protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
       RadGrid1.MasterTableView.GetColumn("UserId").Visible = false;
       RadGrid1.MasterTableView.GetColumn("EntityId").Visible = false;
   }
 
 
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem DeleteEmployee = e.Item as GridEditableItem;
       Hashtable NewValues = new Hashtable();
       e.Item.OwnerTableView.ExtractValuesFromItem(NewValues, DeleteEmployee);
       int EntityId = Convert.ToInt32(DeleteEmployee.GetDataKeyValue("EntityId"));
       int UserId = Convert.ToInt32(NewValues["UserId"].ToString());
       ObjGlobas.DeleteEmployeePermission(UserId,EntityId);
       RadGrid1.Rebind();
       RadWindowManager1.RadAlert("Employee Permission Deleted Successfully!", 325, 200, "Manifest-BI : DELETE", null);
 
   }
Thanks

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Dec 2013, 09:42 AM
Hi Swapnil,

If you want to hide the column and use it code behind, please set Display="false".

ASPX:
<telerik:GridBoundColumn HeaderText="UserID" DataField="UserID" Display="false" UniqueName="UserID" />

Another suggestion is set the column as DataKeyNames.

ASPX:
<MasterTableView DataKeyNames="UserId, EntityId">

Access it in CodeBehind as follows:

C#:
string OrderID = edit.GetDataKeyValue("UserId").ToString();
string OrderID = edit.GetDataKeyValue("EntityId").ToString();

Thanks,
Shinu
0
Swapnil
Top achievements
Rank 1
answered on 11 Dec 2013, 06:30 AM
by writing bound column i am not able to hide column
thanks
0
Accepted
Shinu
Top achievements
Rank 2
answered on 11 Dec 2013, 06:58 AM
Hi Swapnil,

If you hide a BoundColumn using it's Display, we can access it in the code behind as follows:

ASPX:
<telerik:GridBoundColumn UniqueName="UserId" DataField="UserId" HeaderText="UserId"
Display="false">
<telerik:GridBoundColumn UniqueName="EntityId" DataField="EntityId" HeaderText="EntityId"
Display="false">

C#:
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
 {
   GridDataItem item = (GridDataItem)e.Item;
   //Access the hidden columns
   string userid= item["UserId"].Text.ToString();
   string entityid= item["EntityId"].Text.ToString();
   // Your code to Delete
 }

Another way is to use DataKeyNames as i suggested before, hence you don't have to add it as a BoundColumn:

ASPX:
<MasterTableView DataKeyNames="UserId, EntityId">

C#:
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
 {
   GridDataItem item = (GridDataItem)e.Item;
   string userid= item.GetDataKeyValue("UserId").ToString();
   string entityid= item.GetDataKeyValue("EntityId").ToString();
   // Your code to Delete
 }

Please note that we access the items to be deleted using GridDataItem and not GridEditableItem.

Thanks,
Shinu



0
Swapnil
Top achievements
Rank 1
answered on 11 Dec 2013, 07:21 AM
still not working
my code is
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Skin="Outlook" HeaderStyle-Font-Bold="true"
                           AllowSorting="True" CellSpacing="0" GridLines="None" ShowGroupPanel="True" HeaderStyle-Font-Size="13px"
                           HeaderStyle-Font-Names="Verdana" ItemStyle-Font-Names="Verdana" AlternatingItemStyle-Font-Names="Verdana"
                           OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender" OnDeleteCommand="RadGrid1_DeleteCommand">
                           <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true"></PagerStyle>
                           <ClientSettings AllowDragToGroup="True" EnablePostBackOnRowClick="true">
                           </ClientSettings>
                           <MasterTableView >
                               <Columns>
                                <telerik:GridBoundColumn HeaderText="UserId" DataField="UserId" Display="false" UniqueName="UserId" Visible="false" />
                                   <telerik:GridBoundColumn HeaderText="EntityId" DataField="EntityId" Display="false" UniqueName="EntityId" Visible="false" />
                                   <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" UniqueName="DeleteColumn"
                                       ConfirmText="Are you sure to Delete this Entity?" ConfirmDialogType="RadWindow"
                                       ConfirmTitle="<b>Manifest-BI</b>">
                                   </telerik:GridButtonColumn>
                               </Columns>
                               <PagerStyle AlwaysVisible="True"></PagerStyle>
                           </MasterTableView>
                       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DeletePermissionGrid = ObjGlobas.DeleteEntityPermission_BindGrid(RoleId,UserId);
        RadGrid1.DataSource = DeletePermissionGrid.Tables[0];
    }
 
 protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        //RadGrid1.MasterTableView.GetColumn("UserId").Visible = false;
        //RadGrid1.MasterTableView.GetColumn("EntityId").Visible = false;
    }
 
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
    {
        //GridEditableItem DeleteEmployee = e.Item as GridEditableItem;
        //Hashtable NewValues = new Hashtable();
        //e.Item.OwnerTableView.ExtractValuesFromItem(NewValues, DeleteEmployee);
        //int EntityId = Convert.ToInt32(DeleteEmployee.GetDataKeyValue("EntityId"));
        //int UserId = Convert.ToInt32(NewValues["UserId"].ToString());
        //ObjGlobas.DeleteEmployeePermission(UserId,EntityId);
        //RadGrid1.Rebind();
        //RadWindowManager1.RadAlert("Employee Permission Deleted Successfully!", 325, 200, "Manifest-BI : DELETE", null);
 
        GridDataItem item = (GridDataItem)e.Item;
        //Access the hidden columns
        string userid = item["UserId"].Text.ToString();
        string entityid = item["EntityId"].Text.ToString();
        // Your code to Delete
 
    }
0
Shinu
Top achievements
Rank 2
answered on 12 Dec 2013, 03:35 AM
Hi Swapnil,

Please remove Visible="false" from your BoundColumns, only set Display="false".

ASPX:
<telerik:GridBoundColumn HeaderText="UserId" DataField="UserId" Display="false" UniqueName="UserId" />
<telerik:GridBoundColumn HeaderText="EntityId" DataField="EntityId" Display="false" UniqueName="EntityId"/>

Thanks,
Shinu

Tags
Grid
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Swapnil
Top achievements
Rank 1
Share this question
or