Hi all,
I've created a new data type named "CustomList" to link two "Form and List" lists (Like master-detail)
But, i have a problem when i specify the that it is "Restricted Form Field" with "Default Value = [QueryString:id]"
It gets the InputSettings value instead
This is the code and i hope to get help
--> Note
- I'm new to UDT and VB ... So, there may be another way to develop it
- I followed the sample http://www.formandlist.com/blog.aspx?id=16011
--------------------------------------------------------------------------------------------------------------------------------------------------
File FormAndList.CustomList.vb
--------------------------------------------
Imports System.Collections.Generic
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Modules.UserDefinedTable
Imports System.Data
Imports System.Web
Imports System.Web.UI.WebControls
Imports DotNetNuke.Entities.Users
Imports Microsoft.ApplicationBlocks.Data
Namespace FormAndList.CustomList
Public Class DataTypeCustomList
Inherits DataType
Public Overrides ReadOnly Property Name() As String
Get
Return "CustomList"
End Get
End Property
Public Overrides ReadOnly Property EditControl() As DotNetNuke.Modules.UserDefinedTable.EditControl
Get
Return New EditCustomList
End Get
End Property
Public Overrides ReadOnly Property SupportsEditing() As Boolean
Get
Return True
End Get
End Property
Public Overrides ReadOnly Property SupportsInputSettings() As Boolean
Get
Return True
End Get
End Property
Public Overrides ReadOnly Property SupportsDefaultValue() As Boolean
Get
Return True
End Get
End Property
Public Overrides Sub RenderValuesToHtmlInsideDataSet(ByVal ds As System.Data.DataSet, ByVal ModuleId As Integer, ByVal noscript As Boolean)
Dim fields As New List(Of String)
Dim tableData As DataTable = ds.Tables(DataSetTableName.Data)
For Each row As DataRow In ds.Tables(DataSetTableName.Fields).Rows
If CStr(row(FieldsTableColumn.Type)) = Name Then
fields.Add(CStr(row(FieldsTableColumn.Title)) + "_" + row.ItemArray(12))
End If
Next
If Not ds Is Nothing And fields.Count > 0 AndAlso HttpContext.Current IsNot Nothing Then
For Each row As DataRow In tableData.Rows
For Each field As String In fields
Dim values = field.Split("_")
Dim CustomlistId As String = CInt(row(values(0)))
If Not String.IsNullOrEmpty(CustomlistId) Then
Dim inputs = values(1).Split(";")
If inputs.Length = 2 Then
Dim cmd As SqlCommand = New SqlCommand
cmd.Connection = New SqlConnection(DotNetNuke.Data.DataProvider.Instance().ConnectionString)
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "UserDefinedTable_CustomList_GetValue"
cmd.Parameters.AddWithValue("@UserDefinedRowId", CustomlistId)
cmd.Parameters.AddWithValue("@ModuleId", inputs(0))
cmd.Parameters.AddWithValue("@FieldTitle", inputs(1))
cmd.Parameters.Add("@FieldValue", SqlDbType.NVarChar, 2000)
cmd.Parameters("@FieldValue").Direction = ParameterDirection.Output
cmd.Connection.Open()
cmd.ExecuteNonQuery()
row(values(0)) = CustomlistId + ";#" + cmd.Parameters("@FieldValue").Value
cmd.Connection.Close()
cmd.Dispose()
End If
End If
Next
Next
End If
End Sub
End Class
Public Class EditCustomList
Inherits EditControl
Protected customList As ListControl
Private Sub EditCustomList_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Select Case ListInputType
Case InputType.horizontalRadioButtons
customList = New RadioButtonList
CType(customList, RadioButtonList).RepeatDirection = RepeatDirection.Horizontal
Case InputType.verticalRadioButtons
customList = New RadioButtonList
Case Else
customList = New DropDownList
End Select
'customList.Items.Add(New ListItem("--", ""))
Dim inputs = InputSettings.Split(";")
If inputs.Length = 2 Then
Dim cmd As SqlCommand = New SqlCommand
cmd.Connection = New SqlConnection(DotNetNuke.Data.DataProvider.Instance().ConnectionString)
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "UserDefinedTable_CustomList_GetList"
cmd.Parameters.AddWithValue("@ModuleId", inputs(0))
cmd.Parameters.AddWithValue("@FieldTitle", inputs(1))
cmd.Connection.Open()
Dim reader = cmd.ExecuteReader()
If reader.HasRows Then
While reader.Read()
customList.Items.Add(New ListItem(reader.Item(0).ToString(), reader.Item(1).ToString()))
End While
End If
reader.Close()
cmd.Connection.Close()
cmd.Dispose()
'Dim dset = (New UserDefinedTableController(inputs(1), inputs(0), New UserInfo())).GetDataSet(True)
'For Each row As DataRow In dset.Tables("Data").Rows
' customList.Items.Add(New ListItem(row(inputs(2)), row("UserDefinedRowId")))
'Next
End If
customList.SelectedValue = DefaultValue
Me.Controls.Add(customList)
End Sub
Public Overrides Property Value() As String
Get
Value = customList.SelectedValue
End Get
Set(ByVal Value As String)
If Not String.IsNullOrEmpty(Value) Then
customList.SelectedValue = Value
Else
customList.SelectedIndex = 0
End If
Me.ViewState("value") = Value
End Set
End Property
End Class
End Namespace
--------------------------------------------------------------------------------------------------------------------------------------------------
In File DataTypes.config
---------------------------------
<dataType name="CustomList" typeName="FormAndList.CustomList.DataTypeCustomList"/>
--------------------------------------------------------------------------------------------------------------------------------------------------
Helper SqlDb Stored Procedures
---------------------------------------------
Create Procedure [dbo].[UserDefinedTable_CustomList_GetList]
@ModuleId int,
@FieldTitle nvarchar(50)
as
Set @FieldTitle = Lower(@FieldTitle)
Select FieldValue, UserDefinedRowId
From UserDefinedData Inner Join
UserDefinedFields on UserDefinedFields.UserDefinedFieldId = UserDefinedData.UserDefinedFieldId
Where ModuleId = @ModuleId
and Lower(FieldTitle) = @FieldTitle
Create procedure [dbo].[UserDefinedTable_CustomList_GetValue]
@UserDefinedRowId int,
@ModuleId int,
@FieldTitle nvarchar(50),
@FieldValue nvarchar(2000) out
as
Set @FieldTitle = Lower(@FieldTitle)
Declare @UserDefinedFieldId int
Select @UserDefinedFieldId = UserDefinedFieldId
From UserDefinedFields
Where ModuleId = @ModuleId and Lower(FieldTitle) = @FieldTitle
Select @FieldValue = FieldValue
From UserDefinedData
Where UserDefinedFieldId = @UserDefinedFieldId
and UserDefinedRowId = @UserDefinedRowId
--------------------------------------------------------------------------------------------------------------------------------------------------
Thanks.