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

GridTableView CommandItem

4 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Srujan
Top achievements
Rank 1
Srujan asked on 08 Nov 2013, 10:39 PM

Hi All

I am using master detail grid and it is working fine . In detail table I have telerik:GridTableView with CommandItemSettings-AddNewRecordText enabled , I want to show/hide this option dynamically in item data bound , I am able to hide it when I use below code but my condition could only be checked when (e.Item is GridDataItem) , I tried to get commanditems using GridItem cmdItem = tableView.GetItems(GridItemType.CommandItem)[0]  but only Null values returned , can anybody suggest how go about the same

if (e.Item is GridCommandItem) 
    { 
        Button addButton = e.Item.FindControl("AddNewRecordButton") as Button; 
        addButton.Visible = false; 
        LinkButton lnkButton = (LinkButton)e.Item.FindControl("InitInsertButton"); 
        lnkButton.Visible = false; 
    }     

 
Thanks
Srujan.N

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 11 Nov 2013, 04:40 AM
Hi Srujan,

I guess you want to hide the AddNewRecordButton for the second radgrid based on the row selected in the first radgrid. Please try the following code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" >
 <ClientSettings  EnablePostBackOnRowClick="true">
  <Selecting AllowRowSelect="true"></Selecting>
 </ClientSettings>  
</telerik:RadGrid>

C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridDataItem item = (GridDataItem)RadGrid1.SelectedItems[0];
    string cus_id = RadGrid1.SelectedValue.ToString();//Retrieving primary key field values for selected items
    // string name = item["ColumnUniqueName"].Text; //Access any other column value
    if (Some Condition)
    {
        //Hide AddNewRecordButton
        RadGrid2.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
    }
    else
    {
        RadGrid2.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = true;
    }
}

Thanks,
Princy
0
Srujan
Top achievements
Rank 1
answered on 11 Nov 2013, 04:03 PM
Hi Princy ,

I have only one Grid where I am using Detail Tables as below , I want hide AddNewButton on detail table based on the selection in MasterTable , can you please suggest how to proceed on the same .

<DetailTables>

<telerik:GridTableView runat="server" >
<DetailTables>

Thanks
Srujan.N

0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Nov 2013, 04:31 PM
Hello,

Please try with the below code snippet.

protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridDataItem item = (GridDataItem)RadGrid1.SelectedItems[0];
        string cus_id = RadGrid1.SelectedValue.ToString();//Retrieving primary key field values for selected items
        // string name = item["ColumnUniqueName"].Text; //Access any other column value
        if (1 == 1) // your condition
        {
            //Hide AddNewRecordButton
            if (item.HasChildItems)
                item.ChildItem.NestedTableViews[0].CommandItemSettings.ShowAddNewRecordButton = false;
        }
 
    }


Let me know if any concern.

Thanks,
Jayesh Goyani
0
Princy
Top achievements
Rank 1
answered on 12 Nov 2013, 06:22 AM
Hi Srujan,

I guess you are expanding the detail table on row select. Please try the following code snippet to hide the AddNewRecordButton for a row selected in MasterTable.

C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridDataItem item = (GridDataItem)RadGrid1.SelectedItems[0];
    string cus_id = RadGrid1.SelectedValue.ToString();
    if (!item.Expanded)
    {
        item.Expanded = true;
        GridTableView detailTable = (GridTableView)item.ChildItem.NestedTableViews[0];
        if (Some Condition)
        {
            GridCommandItem itm = (GridCommandItem)detailTable.GetItems(GridItemType.CommandItem)[0];
            itm.FindControl("AddNewRecordButton").Parent.Visible = false;           
        }
    }
}

Thanks,
Princy
Tags
Grid
Asked by
Srujan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Srujan
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or