Custom control

F

Fraggle

I am trying to make my 1st composite control. It is a simple list with
2x buttons. the final functionality will be to move items in the list
up and down using the buttons.

however I cannot get it to bind to a datasource

here is the code for the control



Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections
Imports Microsoft.VisualBasic
imports System.Data
imports System.Data.SqlClient
imports surveycode
imports ASPNetPortal

namespace SurveyCode

Public Class Ranker : Inherits Control



public AnswersList As System.Web.UI.WebControls.listbox
private upBtn as imagebutton
private downBtn as imagebutton

private _dataSource As DataSet
private _DataTextField As string
private _DataValueField As string

dim answeritems as new arraylist



Public Property DataSource() As DataSet
Get
Me.EnsureChildControls()
Return _datasource

End Get
Set(ByVal value As DataSet)
Me.EnsureChildControls()
_dataSource = value

End Set
End Property


Public Property DataTextField() As String
Get
Me.EnsureChildControls()
Return _DataTextField

End Get
Set(ByVal value As String)
Me.EnsureChildControls()
_DataTextField = value

End Set
End Property

Public Property DataValueField() As String
Get
Me.EnsureChildControls()
Return _DataValueField
End Get
Set(ByVal value As String)
Me.EnsureChildControls()
_DataValueField = value
End Set
End Property

Protected Overrides Sub CreateChildControls()



' Create a text box control, set the default Text property,
' and add it to the ControlCollection.

Dim answerslist As New listbox()
answerslist.id ="al" & me.uniqueID

Dim upBtn As New imagebutton()
AddHandler upbtn.click, AddressOf UpDown_click
upBtn.commandName="up"
upBtn.id = "up" & me.uniqueID

Dim downBtn As New imagebutton()
AddHandler downBtn.click, AddressOf UpDown_click
downBtn.commandName="down"
downBtn.id = "dn" & me.uniqueID

Me.Controls.Add(answerslist)
Me.Controls.Add(upBtn)
Me.Controls.Add(downBtn)


End Sub 'CreateChildControls



Public Overrides Sub DataBind()
MyBase.OnDataBinding(EventArgs.Empty)

CreateList()
End Sub


Private Sub CreateList()


dim drw as datarow

for each drw in dataSource.tables(0).rows

dim a as new surveycode.answerlistitem

a.itemID = drw("itemID")
a.Answer = drw("answer")
a.sort = drw("sort")

answeritems.add(a)

next


AnswersList.datasource=Me.answeritems
AnswersList.DataValueField=me.DataValueField
AnswersList.DataTextField=me.DataTextField
AnswersList.databind()


'end if


End Sub






'order the answers within the list

Sub OrderAnswers()
End Sub

sub UpDown_Click(ByVal sender As Object, ByVal e As
ImageClickEventArgs)
end sub

End Class

End Namespace


In an aspx page i have this

<%@ Register TagPrefix="Surv" Namespace="SurveyCode" Assembly="Ranker"
%>
<script>
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
datasrc2 = Questions.GetAnswersbyQuestion(1)
rank1.datasource = datasrc2
end sub
</script>

<surv:ranker runat="server" id="rank1" />


This code throws up a mini box with the buttons, but no data displays,
if i throw the data at a radiobuttonlist, or checkbox list they do
display.

bit confused :)

Thanks

Fragg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top