I have a little bit of a challenging task, and I am not certain how to go about accomplishing it. I have a grid that loads orders (detail table is the items in an order number) for the purposes of administering them. This will primarily be used for our customer service reps. What I need to do is to make the delete button invisible if the order status = 'pending', because at that point the order cannot be deleted from the web portal, but must rather be deleted using another method. I hope someone can point me in the right direction of how I can accomplish this task. Here's the grid code:
Is there an easy way to load the delete button dynamically as the grid is filled with data based on the value of the order status? At this point, even a starting point would be helpful...
<telerik:RadGrid ID="rgOrderView" runat="server" AllowPaging="True" AllowSorting="True" |
DataSourceID="dsSelectOrders" GridLines="None" Width="95%" PageSize="25" Skin="Black"> |
<MasterTableView AutoGenerateColumns="False" DataSourceID="dsSelectOrders" Width="95%" |
DataKeyNames="UserID, OrderID"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridBoundColumn DataField="ExternalOrderID" DataType="System.Int32" HeaderText="Order ID" |
ReadOnly="True" SortExpression="ExternalOrderID" UniqueName="ExternalOrderID" /> |
<telerik:GridBoundColumn DataField="StoreNum" HeaderText="Store Number" |
SortExpression="StoreNum" UniqueName="StoreNum" /> |
<telerik:GridBoundColumn DataField="POGNum" HeaderText="POG Number" |
SortExpression="POGNum" UniqueName="POGNum" /> |
<telerik:GridBoundColumn DataField="Description" HeaderText="POG Description" |
SortExpression="Description" UniqueName="Description" /> |
<telerik:GridBoundColumn DataField="EntryDate" DataType="System.DateTime" |
HeaderText="Entry Date" SortExpression="EntryDate" UniqueName="EntryDate" /> |
<telerik:GridBoundColumn DataField="Status" HeaderText="Status" SortExpression="Status" |
UniqueName="Status" /> |
<telerik:GridBoundColumn DataField="OrderID" SortExpression="OrderID" UniqueName="OrderID" |
Visible="false"/> |
</Columns> |
<NestedViewSettings DataSourceID="dsSelectOrderDetails"> |
<ParentTableRelation> |
<telerik:GridRelationFields MasterKeyField="OrderID" DetailKeyField="OrderID" /> |
</ParentTableRelation> |
</NestedViewSettings> |
<NestedViewTemplate> |
<telerik:RadGrid ID="rgOrderDetails" runat="server" AutoGenerateColumns="False" DataSourceID="dsSelectOrderDetails" |
AllowSorting="true" AllowFilteringByColumn="true" > |
<MasterTableView AutoGenerateColumns="False" DataSourceID="dsSelectOrderDetails"> |
<Columns> |
<telerik:GridBoundColumn DataField="ItemNum" HeaderText="Item Number" |
SortExpression="ItemNum" UniqueName="ItemNum" /> |
<telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity" |
SortExpression="Quantity" UniqueName="Quantity" /> |
</Columns> |
</MasterTableView> |
<HierarchySettings ExpandTooltip="Expand this Order to see item detail." /> |
</telerik:RadGrid> |
</NestedViewTemplate> |
</MasterTableView> |
</telerik:RadGrid> |
10 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 20 Apr 2010, 05:17 AM
Hello Beemer,
The better solution is you can add a GridButtonColumn for delete button and access it in the ItemDataBound event. From there based on the value of the order status make the delete button visible/invisible. I hope the following code will help you.
aspx:
C#:
Regards,
Shinu.
The better solution is you can add a GridButtonColumn for delete button and access it in the ItemDataBound event. From there based on the value of the order status make the delete button visible/invisible. I hope the following code will help you.
aspx:
<telerik:GridButtonColumn Text="Delete" CommandName="Delete" UniqueName="DeleteButton" /> |
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
GridDataItem item = (GridDataItem)e.Item; |
string status = item["Status"].Text; |
LinkButton DeleteButton = (LinkButton)item["DeleteButton"].Controls[0]; |
if (status == "pending") |
{ |
DeleteButton.Visible = false; |
} |
} |
} |
Regards,
Shinu.
0
TSCGlobal
Top achievements
Rank 1
answered on 20 Apr 2010, 12:09 PM
I'll play around with this idea today. We use vb.net for our codebehind, but I think I can reason it out based on what you've provided. I'll keep you posted. :)
0
TSCGlobal
Top achievements
Rank 1
answered on 20 Apr 2010, 02:32 PM
Ok...this is what I have so far...
.aspx page:
and then in the code behind is as follows:
The "IF" statement there that is "if e.item Is GridDataItem..." is throwing an error...can anyone give me a little syntax help here? I wasn't entirely sure how the C# "translated" here... Once I get that squared away, I can try it out and see if it will work.
Also, the line "Dim DataItem as GridDataItem = e.Item" causes issues. I get the following error:
Unable to cast object of type 'Telerik.Web.UI.GridPagerItem' to type 'Telerik.Web.UI.GridDataItem'.
.aspx page:
<telerik:RadGrid ID="rgOrderView" runat="server" AllowPaging="True" AllowSorting="True" |
DataSourceID="dsSelectOrders" GridLines="None" Width="95%" PageSize="25" |
Skin="Black" AutoGenerateColumns="False"> |
<MasterTableView DataSourceID="dsSelectOrders" Width="95%" |
DataKeyNames="UserID, OrderID"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridBoundColumn DataField="ExternalOrderID" DataType="System.Int32" HeaderText="Order ID" |
ReadOnly="True" SortExpression="ExternalOrderID" UniqueName="ExternalOrderID" /> |
<telerik:GridBoundColumn DataField="StoreNum" HeaderText="Store Number" SortExpression="StoreNum" |
UniqueName="StoreNum" /> |
<telerik:GridBoundColumn DataField="POGNum" HeaderText="POG Number" SortExpression="POGNum" |
UniqueName="POGNum" /> |
<telerik:GridBoundColumn DataField="EntryDate" DataType="System.DateTime" HeaderText="Entry Date" |
SortExpression="EntryDate" UniqueName="EntryDate" /> |
<telerik:GridBoundColumn DataField="Status" HeaderText="Status" SortExpression="Status" |
UniqueName="Status" /> |
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteButton" /> |
</Columns> |
<NestedViewSettings DataSourceID="dsSelectOrderDetails"> |
<ParentTableRelation> |
<telerik:GridRelationFields MasterKeyField="OrderID" DetailKeyField="OrderID" /> |
</ParentTableRelation> |
</NestedViewSettings> |
<NestedViewTemplate> |
<telerik:RadGrid ID="rgOrderDetails" runat="server" AutoGenerateColumns="False" DataSourceID="dsSelectOrderDetails"> |
<MasterTableView AutoGenerateColumns="False" DataSourceID="dsSelectOrderDetails"> |
<Columns> |
<telerik:GridBoundColumn DataField="ItemNum" HeaderText="Item Number" SortExpression="ItemNum" UniqueName="ItemNum" /> |
<telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" UniqueName="Quantity" /> |
</Columns> |
</MasterTableView> |
<HierarchySettings ExpandTooltip="Expand this Order to see item detail." /> |
</telerik:RadGrid> |
</NestedViewTemplate> |
</MasterTableView> |
</telerik:RadGrid> |
Private Sub rgOrderView_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgOrderView.ItemDataBound |
Dim DataItem As GridDataItem = e.Item |
Dim OrderStatus As String |
Dim DeleteButton As LinkButton |
If e.Item Is GridDataItem Then |
OrderStatus = DataItem("Status").Text |
DeleteButton = DataItem("btnDelete").Controls(0) |
If OrderStatus = "pending" Then |
DeleteButton.Visible = False |
End If |
End If |
End Sub |
Also, the line "Dim DataItem as GridDataItem = e.Item" causes issues. I get the following error:
Unable to cast object of type 'Telerik.Web.UI.GridPagerItem' to type 'Telerik.Web.UI.GridDataItem'.
0
TSCGlobal
Top achievements
Rank 1
answered on 21 Apr 2010, 02:27 PM
Ok, I have the master table working, but can't seem to figure out how to get the detail table to do the same thing regarding the delete button. I thought it would be as easy as adding a reference to it as I did the first, but it wouldn't work for me. If anyone could help me out in getting the delete button visibility to = false based on order status of the master table, it would be much appreciated. Here's the working code...
The table is pretty much the same as in my last post.
Private Sub rgOrders_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgOrders.ItemDataBound |
If TypeOf e.Item Is GridDataItem Then |
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
Dim status As String = item("Status").Text |
Dim DeleteButton As LinkButton = DirectCast(item("DeleteButton").Controls(0), LinkButton) |
If status = "Processing" Then |
DeleteButton.Visible = False |
End If |
End If |
End Sub |
0
Hello beemer,
The problem with this code in the context of multiple nested tables is that you may not have the "Status" column in every detail table. Therefore, if you know you need to apply this logic only for the items in the master table, you need to incorporate an additional check for that:
In the above modified code snippet, I am checking if the item for which ItemDataBound event is fired belongs to the master table. If not, I do not want to check for the Status field, because my detail tables do not have a Status field.
If you need to similarly check for other detail tables, you need to give your detail table a Name and check for this name:
Greetings,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
The problem with this code in the context of multiple nested tables is that you may not have the "Status" column in every detail table. Therefore, if you know you need to apply this logic only for the items in the master table, you need to incorporate an additional check for that:
Private
Sub
rgOrders_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
rgOrders.ItemDataBound
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
item
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
If
item.OwnerTableView = rgOrders.MasterTableView
Then
Dim
status
As
String
= item(
"Status"
).Text
Dim
DeleteButton
As
LinkButton =
DirectCast
(item(
"DeleteButton"
).Controls(0), LinkButton)
If
status =
"Processing"
Then
DeleteButton.Visible =
False
End
If
End
If
End
If
End
Sub
In the above modified code snippet, I am checking if the item for which ItemDataBound event is fired belongs to the master table. If not, I do not want to check for the Status field, because my detail tables do not have a Status field.
If you need to similarly check for other detail tables, you need to give your detail table a Name and check for this name:
Private
Sub
rgOrders_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
rgOrders.ItemDataBound
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
item
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
If
item.OwnerTableView.Name =
"MyDetailTableName"
Then
'...
End
If
End
If
End
Sub
Greetings,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
TSCGlobal
Top achievements
Rank 1
answered on 23 Apr 2010, 12:18 PM
Ok, that helps me out a little, but let me make sure I understand this clearly:
If the detail table does NOT have a status column (which it doesn't) I can still remove the delete and edit buttons based on the status of the order from the Master table? This is exactly what I need to do, because an order that is "Processing" means that the order has been pulled off the web portal and put into the accounting/shipping system (it's kinda weird the way this company has this set up...) which means that the order must be deleted/edited in those systems, and not on the web portal database.
Do I still need to name the detail table and add the snippet of code you provided then, because it doesn't seem to be removing the delete/edit buttons in the detail table based on the status column in the master table currently.
If the detail table does NOT have a status column (which it doesn't) I can still remove the delete and edit buttons based on the status of the order from the Master table? This is exactly what I need to do, because an order that is "Processing" means that the order has been pulled off the web portal and put into the accounting/shipping system (it's kinda weird the way this company has this set up...) which means that the order must be deleted/edited in those systems, and not on the web portal database.
Do I still need to name the detail table and add the snippet of code you provided then, because it doesn't seem to be removing the delete/edit buttons in the detail table based on the status column in the master table currently.
0
Accepted
Hello beemer,
It's a little different for your particular scenario then. You still need to give your detail table a name, though. Unless you have a single nested level, in which case you could simply check if the owner table is different from the master table, which would imply the table is the nested one.
So, to clarify. The master table has a delete column and a Status field. The detail table does not have a Status field, but has a delete column as well. You need the delete buttons removed for parent items that have a "Processing" , as well as their nested items.
If I got you correct, here is the modified ItemDataBound event handler:
So, in the above snippet, I extract the Status field in 2 cases. The first case is when the current databound item (e.Item) is from the master table. In this case, the item itself has a Status field, whose text I get directly.
The second case is when the current item (e.Item) is from the detail table. In this case, I need to get to the parent data item, that is the item from the master table that has a child table containing the current item.
Once I find the status value, the logic for both cases is identical. I have a delete column in both the master and the detail table, so, in either case, I need to find and hide that button.
As I mentioned above, the only assumption this piece of code does is that there is a single level of nested tables. Therefore an item can belong either to the master table, or to the detail table. If there were more nested levels, things would have gotten a little more complicated in terms of finding the Status field from the topmost master table.
Let me know how that works for you.
Kind regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
It's a little different for your particular scenario then. You still need to give your detail table a name, though. Unless you have a single nested level, in which case you could simply check if the owner table is different from the master table, which would imply the table is the nested one.
So, to clarify. The master table has a delete column and a Status field. The detail table does not have a Status field, but has a delete column as well. You need the delete buttons removed for parent items that have a "Processing" , as well as their nested items.
If I got you correct, here is the modified ItemDataBound event handler:
Private
Sub
rgOrders_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
rgOrders.ItemDataBound
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
item
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
Dim
status
As
String
=
String
.Empty
If
item.OwnerTableView = rgOrders.MasterTableView
Then
status = item(
"Status"
).Text
Else
status = item.OwnerTableView.ParentItem(
"Status"
).Text;
End
If
Dim
DeleteButton
As
LinkButton =
DirectCast
(item(
"DeleteButton"
).Controls(0), LinkButton)
If
status =
"Processing"
Then
DeleteButton.Visible =
False
End
If
End
If
End
Sub
So, in the above snippet, I extract the Status field in 2 cases. The first case is when the current databound item (e.Item) is from the master table. In this case, the item itself has a Status field, whose text I get directly.
The second case is when the current item (e.Item) is from the detail table. In this case, I need to get to the parent data item, that is the item from the master table that has a child table containing the current item.
Once I find the status value, the logic for both cases is identical. I have a delete column in both the master and the detail table, so, in either case, I need to find and hide that button.
As I mentioned above, the only assumption this piece of code does is that there is a single level of nested tables. Therefore an item can belong either to the master table, or to the detail table. If there were more nested levels, things would have gotten a little more complicated in terms of finding the Status field from the topmost master table.
Let me know how that works for you.
Kind regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
TSCGlobal
Top achievements
Rank 1
answered on 26 Apr 2010, 02:11 PM
This works for the master table, but the delete/edit buttons still appear in the detail table. The nested view has another Rad Grid in it. Here's the table .aspx code:
If there's a better way to do the nested view, I'd be more than willing to change it to make this work. I used the code you included, with one modification. For the line:
If item.OwnerTableView = rgOrders.MasterTableView Then
I changed it because I was getting an error that said;
Error 1 Operator '=' is not defined for types 'Telerik.Web.UI.GridTableView' and 'Telerik.Web.UI.GridTableView'.
So the modified code looks like this:
<telerik:RadGrid ID="rgOrders" runat="server" DataSourceID="dsSelectOrders" GridLines="None"> |
<MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" DataSourceID="dsSelectOrders"> |
<Columns> |
<telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" |
ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID" Visible="false"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="ExternalOrderID" DataType="System.Int32" |
HeaderText="Order ID" ReadOnly="True" SortExpression="ExternalOrderID" |
UniqueName="ExternalOrderID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="StoreNum" HeaderText="Store #" |
SortExpression="StoreNum" UniqueName="StoreNum"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="POGNum" HeaderText="POG #" |
SortExpression="POGNum" UniqueName="POGNum"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="EntryDate" DataType="System.DateTime" |
HeaderText="Entry Date" SortExpression="EntryDate" UniqueName="EntryDate"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="UserID" HeaderText="User ID" |
SortExpression="UserID" UniqueName="UserID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Status" HeaderText="Status" |
SortExpression="Status" UniqueName="Status"> |
</telerik:GridBoundColumn> |
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" |
UniqueName="DeleteButton"> |
</telerik:GridButtonColumn> |
<telerik:GridEditCommandColumn ButtonType="LinkButton"> |
</telerik:GridEditCommandColumn> |
</Columns> |
<NestedViewSettings DataSourceID="dsSelectOrderDetails"> |
<ParentTableRelation> |
<telerik:GridRelationFields MasterKeyField="OrderID" DetailKeyField="OrderID" /> |
</ParentTableRelation> |
</NestedViewSettings> |
<NestedViewTemplate> |
<telerik:RadGrid ID="rgOrderDetails" runat="server" AutoGenerateColumns="False" |
DataSourceID="dsSelectOrderDetails" AllowSorting="true" AllowFilteringByColumn="true"> |
<MasterTableView AutoGenerateColumns="False" DataSourceID="dsSelectOrderDetails"> |
<Columns> |
<telerik:GridBoundColumn DataField="ItemNum" HeaderText="Item Number" |
SortExpression="ItemNum" UniqueName="ItemNum" /> |
<telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity" |
SortExpression="Quantity" UniqueName="Quantity" /> |
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" |
UniqueName="DeleteButton2"> |
</telerik:GridButtonColumn> |
<telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="EditCommandColumn"> |
</telerik:GridButtonColumn> |
</Columns> |
</MasterTableView> |
<HierarchySettings ExpandTooltip="Expand this Order to see item detail." /> |
</telerik:RadGrid> |
</NestedViewTemplate> |
<EditFormSettings> |
<EditColumn ButtonType="LinkButton" EditText="Edit" InsertText="Insert" UpdateText="Update" |
CancelText="cancel" UniqueName="EditCommandColumn1"> |
</EditColumn> |
</EditFormSettings> |
</MasterTableView> |
</telerik:RadGrid> |
If item.OwnerTableView = rgOrders.MasterTableView Then
I changed it because I was getting an error that said;
Error 1 Operator '=' is not defined for types 'Telerik.Web.UI.GridTableView' and 'Telerik.Web.UI.GridTableView'.
So the modified code looks like this:
Private Sub rgOrders_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgOrders.ItemDataBound |
If TypeOf e.Item Is GridDataItem Then |
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
Dim status As String = String.Empty |
Dim EditButton As LinkButton = DirectCast(item("EditCommandColumn").Controls(0), LinkButton) |
If item.OwnerTableView Is rgOrders.MasterTableView Then |
status = item("Status").Text |
Else |
status = item.OwnerTableView.ParentItem("Status").Text |
End If |
Dim DeleteButton As LinkButton = DirectCast(item("DeleteButton").Controls(0), LinkButton) |
If status = "Processing" Then |
DeleteButton.Visible = False |
EditButton.Visible = False |
End If |
End If |
End Sub |
0
Hi beemer,
The scenario you are using is just fine and we can get this working without you having to change the way you have setup your hierarchy. So, to clarify, the example ItemDataBound event I sent you referred to the scenario where you have nested table views in a single RadGrid. In your case, you have a NestedViewTemplate with a second RadGrid inside, in which situation, the ItemDataBound event should be different and I apologize for misleading you. Try the following instead:
ItemDataBound event handler for parent RadGrid (rgOrders):
ItemDataBound event handler for nested RadGrid (rgOrderDetails):
In the above two event handlers, we check the Status of the current grid item for the parent rgOrders grid and hide the Delete and Edit buttons. For the nested grid, however, we check the Status text of the parent Grid item that is holding the current inner grid in its nested view template. I think this should work for you now.
Best wishes,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
The scenario you are using is just fine and we can get this working without you having to change the way you have setup your hierarchy. So, to clarify, the example ItemDataBound event I sent you referred to the scenario where you have nested table views in a single RadGrid. In your case, you have a NestedViewTemplate with a second RadGrid inside, in which situation, the ItemDataBound event should be different and I apologize for misleading you. Try the following instead:
ItemDataBound event handler for parent RadGrid (rgOrders):
Private
Sub
rgOrders_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
rgOrders.ItemDataBound
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
item
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
Dim
status
As
String
= item(
"Status"
).Text
Dim
EditButton
As
LinkButton =
DirectCast
(item(
"EditCommandColumn"
).Controls(0), LinkButton)
Dim
DeleteButton
As
LinkButton =
DirectCast
(item(
"DeleteButton"
).Controls(0), LinkButton)
If
status =
"Processing"
Then
DeleteButton.Visible =
False
EditButton.Visible =
False
End
If
End
If
End
Sub
ItemDataBound event handler for nested RadGrid (rgOrderDetails):
Private
Sub
rgOrderDetails_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
item
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
Dim
EditButton
As
LinkButton =
DirectCast
(item(
"EditCommandColumn"
).Controls(0), LinkButton)
Dim
DeleteButton
As
LinkButton =
DirectCast
(item(
"DeleteButton"
).Controls(0), LinkButton)
Dim
parentNestedViewItem =
DirectCast
(item.OwnerTableView.OwnerGrid.NamingContainer, Telerik.Web.UI.GridNestedViewItem)
Dim
status
As
String
= parentNestedViewItem.ParentItem(
"Status"
).Text
If
status =
"Processing"
Then
DeleteButton.Visible =
False
EditButton.Visible =
False
End
If
End
If
End
Sub
In the above two event handlers, we check the Status of the current grid item for the parent rgOrders grid and hide the Delete and Edit buttons. For the nested grid, however, we check the Status text of the parent Grid item that is holding the current inner grid in its nested view template. I think this should work for you now.
Best wishes,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
TSCGlobal
Top achievements
Rank 1
answered on 29 Apr 2010, 05:42 PM
I could never get it working with the nested view (grid within a grid). I changed it to a detail table. Here's the final code;
*.aspx code:
here's the vb.net code:
Thanks to everyone for the help.
*.aspx code:
<telerik:RadGrid ID="rgOrders" runat="server" DataSourceID="dsSelectOrders" GridLines="None"> |
<MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" DataSourceID="dsSelectOrders"> |
<ExpandCollapseColumn Visible="True"> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" |
ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID" Visible="false" |
HeaderTooltip="Click the column name to sort in ascending or descending form."> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="ExternalOrderID" DataType="System.Int32" |
HeaderText="Order ID" ReadOnly="True" SortExpression="ExternalOrderID" |
UniqueName="ExternalOrderID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="StoreNum" HeaderText="Store #" |
SortExpression="StoreNum" UniqueName="StoreNum"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="POGNum" HeaderText="POG #" |
SortExpression="POGNum" UniqueName="POGNum"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="EntryDate" DataType="System.DateTime" |
HeaderText="Entry Date" SortExpression="EntryDate" UniqueName="EntryDate"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="UserID" HeaderText="User ID" |
SortExpression="UserID" UniqueName="UserID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Status" HeaderText="Status" |
SortExpression="Status" UniqueName="Status"> |
</telerik:GridBoundColumn> |
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" |
UniqueName="DeleteButton"> |
</telerik:GridButtonColumn> |
<telerik:GridEditCommandColumn ButtonType="LinkButton"> |
</telerik:GridEditCommandColumn> |
</Columns> |
<DetailTables> |
<telerik:GridTableView runat="server" DataSourceID="dsSelectOrderDetails" |
DataKeyNames="OrderID" AllowPaging="True" AllowSorting="True" |
GridLines="Horizontal"> |
<ParentTableRelation> |
<telerik:GridRelationFields MasterKeyField="OrderID" DetailKeyField="OrderID" /> |
</ParentTableRelation> |
<Columns> |
<telerik:GridBoundColumn DataField="ItemNum" HeaderText="Item Number" SortExpression="ItemNum" |
UniqueName="ItemNum" /> |
<telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" |
UniqueName="Quantity" /> |
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteButton" /> |
<telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="EditCommandColumn" /> |
</Columns> |
<EditFormSettings> |
<EditColumn UniqueName="EditCommandColumn1"> |
</EditColumn> |
</EditFormSettings> |
</telerik:GridTableView> |
</DetailTables> |
<EditFormSettings> |
<EditColumn UniqueName="EditCommandColumn1"> |
</EditColumn> |
</EditFormSettings> |
</MasterTableView> |
</telerik:RadGrid> |
here's the vb.net code:
Private Sub rgOrders_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgOrders.ItemDataBound |
If TypeOf e.Item Is GridDataItem Then |
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
Dim status As String = String.Empty |
If item.OwnerTableView Is rgOrders.MasterTableView Then |
status = item("Status").Text |
Else |
status = item.OwnerTableView.ParentItem("Status").Text |
End If |
Dim DeleteButton As LinkButton = DirectCast(item("DeleteButton").Controls(0), LinkButton) |
Dim EditButton As LinkButton = DirectCast(item("EditCommandColumn").Controls(0), LinkButton) |
If status = "Processing" Then |
DeleteButton.Visible = False |
EditButton.Visible = False |
End If |
End If |
End Sub |
Thanks to everyone for the help.