RadControls for ASP.NET AJAX
There are cases in which you may want to identify to which level of the hierarchy the currently created/bound row is. This is suitable when you would like to undertake a task (formatting a row, binding values to its column editors or attaching client events to them when a row is in edit mode, etc.).To identify the table to which the current row belongs/is bound (in the ItemCreated/ItemDataBound handler), you can use the DataMember property of the respective GridTableView (under NET 2.x/3.x when you do not populate the nested table content through data source control) or the DataSourceID property (.NET 2.x/NET 3.x). The third option is to utilize the Name property of each GridTableView (applicable for NET 2.x and NET 3.x) assigning unique value for it beforehand.Below are some sample code snippets:
Without data source controls
CopyC#
private void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.OwnerTableView.DataMember == "MyDataMember")
{
}
}
private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.OwnerTableView.DataMember == "MyDataMember")
{
}
}
CopyVB.NET
Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
If (e.Item.OwnerTableView.DataMember = "MyDataMember") Then
End If
End Sub
Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
If (e.Item.OwnerTableView.DataMember = "MyDataMember") Then
End If
End SubWith data source controls
CopyC#
private void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.OwnerTableView.DataSourceID == "MyDataSourceID")
{
}
}
private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.OwnerTableView.DataSourceID == "MyDataSourceID")
{
}
}
CopyVB.NET
Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
If (e.Item.OwnerTableView.DataSourceID = "MyDataSourceID") Then
End If
End Sub
Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
If (e.Item.OwnerTableView.DataSourceID = "MyDataSourceID") Then
End If
End SubUsing Name property
CopyC#
private void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.OwnerTableView.Name == "MyUniqueTableName")
{
}
}
private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.OwnerTableView.Name == "MyUniqueTableName")
{
}
}
CopyVB.NET
Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
If (e.Item.OwnerTableView.Name = "MyUniqueTableName") Then
End If
End Sub
Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
If (e.Item.OwnerTableView.Name = "MyUniqueTableName") Then
End If
End Sub