Hi,
I added a radgrid with nested template in my web part for sharepoint 2010. I managed to get the radgrid to display items from sharepoint lists but I can't seem to trigger any update or insert events. I have attached my codes as follows.
I added a radgrid with nested template in my web part for sharepoint 2010. I managed to get the radgrid to display items from sharepoint lists but I can't seem to trigger any update or insert events. I have attached my codes as follows.
<%@
Assembly
Name=
"$SharePoint.Project.AssemblyFullName$"
%>
<%@
Assembly
Name=
"Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
%>
<%@ Register TagPrefix=
"SharePoint"
Namespace
=
"Microsoft.SharePoint.WebControls"
Assembly
=
"Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
%>
<%@ Register TagPrefix=
"Utilities"
Namespace
=
"Microsoft.SharePoint.Utilities"
Assembly
=
"Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
%>
<%@ Register TagPrefix=
"asp"
Namespace
=
"System.Web.UI"
Assembly
=
"System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
%>
<%@ Import
Namespace
=
"Microsoft.SharePoint"
%>
<%@ Register TagPrefix=
"WebPartPages"
Namespace
=
"Microsoft.SharePoint.WebPartPages"
Assembly
=
"Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
%>
<%@ Control Language=
"VB"
AutoEventWireup=
"true"
CodeBehind=
"ERM_RiskReportingUserControl.ascx.vb"
Inherits
=
"ERMWeb.ERM_RiskReportingUserControl"
%>
<%@ Register
Assembly
=
"Telerik.Web.UI, Version=2011.1.614.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
Namespace
=
"Telerik.Web.UI"
TagPrefix=
"telerik"
%>
<telerik:RadGrid ID=
"RadGrid1"
runat=
"server"
AutoGenerateColumns=
"False"
GridLines=
"Horizontal"
AllowAutomaticDeletes=
"True"
AllowAutomaticInserts=
"True"
AllowAutomaticUpdates=
"True"
CellSpacing=
"0"
>
<MasterTableView DataKeyNames=
"ID"
CommandItemDisplay=
"Top"
EditMode=
"InPlace"
EnableColumnsViewState=
"false"
>
<Columns>
<telerik:GridBoundColumn DataField=
"ID"
HeaderText=
"ID"
UniqueName=
"ID"
ReadOnly
=
"true"
ItemStyle-Width=
"20px"
/>
<telerik:GridEditCommandColumn UniqueName=
"EditCommandColumn"
ButtonType=
"ImageButton"
ItemStyle-Width=
"50px"
/>
<telerik:GridBoundColumn DataField=
"Strategy"
HeaderText=
"Strategy"
UniqueName=
"Strategy"
ItemStyle-Width=
"400px"
/>
<telerik:GridBoundColumn DataField=
"RiskFactor"
HeaderText=
"Risk Factor"
UniqueName=
"RiskFactor"
ItemStyle-Width=
"400px"
/>
<telerik:GridBoundColumn DataField=
"RiskOwner"
HeaderText=
"Risk Owner"
UniqueName=
"RiskOwner"
ItemStyle-Width=
"300px"
/>
<telerik:GridDropDownColumn DataField=
"Impact"
HeaderText=
"Impact"
UniqueName=
"Impact"
ItemStyle-Width=
"80px"
/>
<telerik:GridDropDownColumn DataField=
"Likelihood"
HeaderText=
"Likelihood"
UniqueName=
"Likelihood"
ItemStyle-Width=
"80px"
/>
</Columns>
<NestedViewSettings>
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField=
"ID"
MasterKeyField=
"ID"
/>
</ParentTableRelation>
</NestedViewSettings>
<NestedViewTemplate>
<table cellpadding=
"30px"
>
<tr>
<td>
<telerik:RadGrid ID=
"RadGrid2"
runat=
"server"
Skin=
"WebBlue"
OnItemDataBound=
"RadGrid2_ItemDataBound"
OnNeedDataSource=
"RadGrid2_NeedDataSource"
AutoGenerateColumns=
"false"
AllowAutomaticInserts=
"True"
AllowAutomaticUpdates=
"True"
>
<ClientSettings EnableRowHoverStyle=
"False"
>
<Selecting AllowRowSelect=
"True"
/>
</ClientSettings>
<MasterTableView DataKeyNames=
"RiskItemID"
CommandItemDisplay=
"Top"
EditMode=
"InPlace"
>
<Columns>
<telerik:GridBoundColumn DataField=
"ID"
HeaderText=
"ID"
UniqueName=
"ID"
ReadOnly
=
"true"
ItemStyle-Width=
"20px"
/>
<telerik:GridEditCommandColumn UniqueName=
"EditCommandColumn"
ButtonType=
"ImageButton"
ItemStyle-Width=
"50px"
/>
<telerik:GridBoundColumn DataField=
"RiskConsequence"
HeaderText=
"Risk Consequence"
UniqueName=
"RiskConsequence"
ItemStyle-Width=
"250px"
/>
<telerik:GridBoundColumn DataField=
"RiskCause"
HeaderText=
"Risk Cause"
UniqueName=
"RiskCause"
ItemStyle-Width=
"250px"
/>
<telerik:GridBoundColumn DataField=
"CurrentMitigation"
HeaderText=
"Current Mitigation"
UniqueName=
"CurrentMitigation"
ItemStyle-Width=
"300px"
/>
<telerik:GridBoundColumn DataField=
"ProposedMitigation"
HeaderText=
"Proposed Mitigation"
UniqueName=
"ProposedMitigation"
ItemStyle-Width=
"300px"
/>
<telerik:GridBoundColumn DataField=
"ImplementationPlan"
HeaderText=
"Implementation Plan"
UniqueName=
"ImplementationPlan"
ItemStyle-Width=
"150px"
/>
<telerik:GridDropDownColumn DataField=
"RiskItemID"
HeaderText=
""
UniqueName=
"RiskItemID"
Visible=
"false"
ItemStyle-Width=
"0px"
/>
</Columns>
<EditFormSettings>
<EditColumn ButtonType=
"ImageButton"
/>
</EditFormSettings>
<EditItemStyle VerticalAlign=
"Top"
/>
</MasterTableView>
</telerik:RadGrid>
</td>
</tr>
</table>
</NestedViewTemplate>
<EditFormSettings>
<EditColumn ButtonType=
"ImageButton"
/>
</EditFormSettings>
<EditItemStyle VerticalAlign=
"Top"
/>
</MasterTableView>
</telerik:RadGrid>
Imports
System
Imports
System.Web.UI
Imports
System.Web.UI.WebControls
Imports
System.Web.UI.WebControls.WebParts
Imports
Telerik.Web.UI
Partial
Public
Class
RiskReportingUserControl
Inherits
UserControl
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
Me
.Load
Me
.EnableViewState =
True
If
Not
Me
.IsPostBack
Then
'BindToGrid()
DisplayMessage(
"No text"
)
End
If
End
Sub
Protected
Function
GetParentGridTable()
As
DataTable
Dim
oSiteCollection
As
SPSite = SPContext.Current.Site
Dim
oWebsiteRoot
As
SPWeb = oSiteCollection.OpenWeb()
Dim
myList
As
Microsoft.SharePoint.SPList
myList = oWebsiteRoot.Lists(
"RiskItem"
)
Dim
results
As
SPListItemCollection = myList.Items
Dim
tbl
As
New
DataTable()
tbl.Columns.Add(
"ID"
,
GetType
(
String
))
tbl.Columns.Add(
"Strategy"
,
GetType
(
String
))
tbl.Columns.Add(
"RiskFactor"
,
GetType
(
String
))
tbl.Columns.Add(
"RiskOwner"
,
GetType
(
String
))
tbl.Columns.Add(
"Impact"
,
GetType
(
String
))
tbl.Columns.Add(
"Likelihood"
,
GetType
(
String
))
Dim
row
As
DataRow
For
Each
result
As
SPListItem
In
results
row = tbl.Rows.Add()
row(
"ID"
) = result(
"ID"
).ToString()
row(
"Strategy"
) = result(
"Strategy"
).ToString()
row(
"RiskFactor"
) = result(
"RiskFactor"
).ToString()
row(
"RiskOwner"
) = result(
"RiskOwner"
).ToString()
row(
"Impact"
) = result(
"Impact"
).ToString()
row(
"Likelihood"
) = result(
"Likelihood"
).ToString()
Next
Return
tbl
End
Function
Protected
Function
GetChildGridTable()
As
DataTable
Dim
oSiteCollection
As
SPSite = SPContext.Current.Site
Dim
oWebsiteRoot
As
SPWeb = oSiteCollection.OpenWeb()
Dim
myList
As
Microsoft.SharePoint.SPList
myList = oWebsiteRoot.Lists(
"RiskItemDetail"
)
Dim
results
As
SPListItemCollection = myList.Items
Dim
tbl
As
New
DataTable()
tbl.Columns.Add(
"ID"
,
GetType
(
String
))
tbl.Columns.Add(
"RiskItemID"
,
GetType
(
String
))
tbl.Columns.Add(
"RiskConsequence"
,
GetType
(
String
))
tbl.Columns.Add(
"RiskCause"
,
GetType
(
String
))
tbl.Columns.Add(
"CurrentMitigation"
,
GetType
(
String
))
tbl.Columns.Add(
"ProposedMitigation"
,
GetType
(
String
))
tbl.Columns.Add(
"ImplementationPlan"
,
GetType
(
String
))
Dim
row
As
DataRow
For
Each
result
As
SPListItem
In
results
row = tbl.Rows.Add()
row(
"ID"
) = result(
"ID"
).ToString()
row(
"RiskItemID"
) = result(
"RiskItemID"
).ToString().Remove(1)
row(
"RiskConsequence"
) = result(
"RiskConsequence"
).ToString()
row(
"RiskCause"
) = result(
"RiskCause"
).ToString()
row(
"CurrentMitigation"
) = result(
"CurrentMitigation"
).ToString()
row(
"ProposedMitigation"
) = result(
"ProposedMitigation"
).ToString()
row(
"ImplementationPlan"
) = result(
"ImplementationPlan"
).ToString()
Next
Return
tbl
End
Function
Protected
Sub
BindToGrid()
RadGrid1.DataSource = GetParentGridTable().DefaultView
RadGrid1.DataBind()
End
Sub
Protected
Sub
RadGrid1_NeedDataSource(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Handles
RadGrid1.NeedDataSource
RadGrid1.DataSource = GetParentGridTable().DefaultView
End
Sub
Protected
Sub
RadGrid2_NeedDataSource(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Dim
grid
As
RadGrid =
DirectCast
(source, RadGrid)
Dim
parentGridItem
As
GridDataItem = TryCast(TryCast(grid.NamingContainer, GridNestedViewItem).ParentItem, GridDataItem)
grid.DataSource = GetChildGridTable().
Select
(
"RiskItemID = "
& parentGridItem.GetDataKeyValue(
"ID"
).ToString())
End
Sub
Protected
Sub
RadGrid1_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
RadGrid1.ItemDataBound
If
TypeOf
e.Item
Is
GridEditableItem
AndAlso
e.Item.IsInEditMode
Then
End
If
If
TypeOf
e.Item
Is
GridDataItem
AndAlso
e.Item.IsInEditMode
Then
Dim
item
As
GridDataItem = TryCast(e.Item, GridDataItem)
Dim
textItem1
As
TextBox =
DirectCast
(item(
"Strategy"
).Controls(0), TextBox)
textItem1.TextMode = TextBoxMode.MultiLine
textItem1.Wrap =
True
textItem1.Width = 400
textItem1.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
textItem1.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
textItem1.Rows = 10
textItem1.Text = textItem1.Text.Replace(
"<br/>"
, Chr(10))
Dim
textItem2
As
TextBox =
DirectCast
(item(
"RiskFactor"
).Controls(0), TextBox)
textItem2.TextMode = TextBoxMode.MultiLine
textItem2.Wrap =
True
textItem2.Width = 400
textItem2.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
textItem2.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
textItem2.Rows = 10
textItem2.Text = textItem2.Text.Replace(
"<br/>"
, Chr(10))
Dim
textItem3
As
TextBox =
DirectCast
(item(
"RiskOwner"
).Controls(0), TextBox)
textItem3.TextMode = TextBoxMode.MultiLine
textItem3.Wrap =
True
textItem3.Width = 300
textItem3.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
textItem3.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
textItem3.Rows = 3
textItem3.Text = textItem3.Text.Replace(
"<br/>"
, Chr(10))
Dim
ddl1
As
RadComboBox =
DirectCast
(item(
"Impact"
).Controls(0), RadComboBox)
ddl1.Width = 80
ddl1.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
ddl1.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
Dim
ddl2
As
RadComboBox =
DirectCast
(item(
"Likelihood"
).Controls(0), RadComboBox)
ddl2.Width = 80
ddl2.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
ddl2.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
End
If
End
Sub
Protected
Sub
RadGrid2_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
If
TypeOf
e.Item
Is
GridDataItem
AndAlso
e.Item.IsInEditMode
Then
Dim
item
As
GridDataItem = TryCast(e.Item, GridDataItem)
Dim
textItem1
As
TextBox =
DirectCast
(item(
"RiskConsequence"
).Controls(0), TextBox)
textItem1.TextMode = TextBoxMode.MultiLine
textItem1.Wrap =
True
textItem1.Width = 250
textItem1.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
textItem1.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
textItem1.Rows = 10
textItem1.Text = textItem1.Text.Replace(
"<br/>"
, Chr(10))
Dim
textItem2
As
TextBox =
DirectCast
(item(
"RiskCause"
).Controls(0), TextBox)
textItem2.TextMode = TextBoxMode.MultiLine
textItem2.Wrap =
True
textItem2.Width = 250
textItem2.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
textItem2.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
textItem2.Rows = 10
textItem2.Text = textItem2.Text.Replace(
"<br/>"
, Chr(10))
Dim
textItem3
As
TextBox =
DirectCast
(item(
"CurrentMitigation"
).Controls(0), TextBox)
textItem3.TextMode = TextBoxMode.MultiLine
textItem3.Wrap =
True
textItem3.Width = 300
textItem3.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
textItem3.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
textItem3.Rows = 10
textItem3.Text = textItem3.Text.Replace(
"<br/>"
, Chr(10))
Dim
textItem4
As
TextBox =
DirectCast
(item(
"ProposedMitigation"
).Controls(0), TextBox)
textItem4.TextMode = TextBoxMode.MultiLine
textItem4.Wrap =
True
textItem4.Width = 300
textItem4.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
textItem4.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
textItem4.Rows = 10
textItem4.Text = textItem4.Text.Replace(
"<br/>"
, Chr(10))
Dim
textItem5
As
TextBox =
DirectCast
(item(
"ImplementationPlan"
).Controls(0), TextBox)
textItem5.TextMode = TextBoxMode.MultiLine
textItem5.Wrap =
True
textItem5.Width = 150
textItem5.Style.Add(
"border"
,
"1px solid #CCCCCC"
)
textItem5.Style.Add(
"font"
,
"10pt tahoma,sans-serif"
)
textItem5.Rows = 10
textItem5.Text = textItem5.Text.Replace(
"<br/>"
, Chr(10))
End
If
End
Sub
Protected
Sub
RadGrid1_ItemInserted(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridInsertedEventArgs)
Handles
RadGrid1.ItemInserted
If
Not
e.Exception
Is
Nothing
Then
e.ExceptionHandled =
True
e.KeepInInsertMode =
True
SetMessage(
"Product cannot be inserted. Reason: "
+ e.Exception.Message)
Else
SetMessage(
"New product is inserted!"
)
End
If
End
Sub
Protected
Sub
RadGrid1_ItemUpdated(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridUpdatedEventArgs)
Handles
RadGrid1.ItemUpdated
Dim
item
As
GridEditableItem =
DirectCast
(e.Item, GridEditableItem)
Dim
id
As
String
= item.GetDataKeyValue(
"ID"
).ToString()
If
Not
e.Exception
Is
Nothing
Then
e.KeepInEditMode =
True
e.ExceptionHandled =
True
SetMessage(
"Risk "
+ id +
" cannot be updated. Reason: "
+ e.Exception.Message)
Else
SetMessage(
"Risk "
+ id +
" is updated!"
)
End
If
End
Sub
Private
Sub
DisplayMessage(
ByVal
text
As
String
)
RadGrid1.Controls.Add(
New
LiteralControl(
String
.Format(
"<span style='color:red'>{0}</span>"
, text)))
End
Sub
Private
Sub
SetMessage(
ByVal
message
As
String
)
gridMessage = message
End
Sub
Private
gridMessage
As
String
=
Nothing
Protected
Sub
RadGrid1_DataBound(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
RadGrid1.DataBound
If
Not
String
.IsNullOrEmpty(gridMessage)
Then
DisplayMessage(gridMessage)
End
If
End
Sub
End
Class