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

Edit rows based on two criteria

3 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tamás
Top achievements
Rank 1
Tamás asked on 17 Dec 2013, 09:41 PM
Hi All,
I am new to Telerik, and after reading some community articles i still cannot do a trick with radgrid. The situation is the following:

I have to do a grid, were the lines can be edited according to permissions:
I have a MasterTableView  with Name="parent" and a detail gridtableview with name "child". I would like to add Edit column for all the rows in detail gridview taking consideration two things:
-who is logged in (windows authentication - i have the user's name in a string)
-what is the content of a column (plant_name) in the "parent" row

So for example: if user Steve is logged in, and he expands the row where plant_name cloumn is "New York" there will be no edit in the details, but if he expands row with plant_name "Toronto" then all the lines in the child gridview can be edited.

I hope i can explain well what i need, and it can be done via Telerik grid.

Thanks!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Dec 2013, 06:25 AM
Hi Tamas,

Please try the following code snippet:

ASPX:
<MasterTableView DataKeyNames="UserName" Name="Parent">
. . . .
<telerik:GridTableView DataKeyNames="name" Name="Child">
. . . .
<telerik:GridEditCommandColumn UniqueName="ChildEdit"></telerik:GridEditCommandColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Child")
    {
        GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
        string name= parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["UserName"].ToString();// Access datakeyValue
        string plant_name = parentItem["plant_name "].Text; //Get the plant_name column values
        if (plant_name == "NewYork" && name=="Steve") //Check your conditions
        {
            GridTableView childtable = (GridTableView)e.Item.OwnerTableView;             
            GridEditCommandColumn btn = (GridEditCommandColumn)childtable.GetColumn("ChildEdit");
            btn.Visible = false;
        }
    }
}

Thanks,
Shinu
0
Tamás
Top achievements
Rank 1
answered on 18 Dec 2013, 12:25 PM
Many thanks! It is working fine.. one more thing: can you tell me how can i make readonly columns in the child grid?
0
Shinu
Top achievements
Rank 2
answered on 19 Dec 2013, 03:51 AM
Hi Tamas,

I'm not sure about your requirement. In order to set a column ReadOnly, the columns have property ReadOnly, set it to true.

ASPX:
<telerik:GridBoundColumn ReadOnly="true" HeaderText="OrderID" HeaderButtonType="TextButton" DataField="OrderID" />

Thanks,
Shinu
Tags
Grid
Asked by
Tamás
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tamás
Top achievements
Rank 1
Share this question
or