Adding Controls that are not a checkboxlist of radiobuttonlist

G

Gummy

Hello,

I know I can use a Checkboxlist or a RadioButtonList to easily create a list
based on the data passed to it.

But using what if I wanted to use the same data and based on the data,
return either a textbox or checkbox (or even a user control). What is the
best way to do that?

Thanks for the help.

-Gummy
 
S

S. Justin Gengo

Gummy,

In the situation you describe I would use a repeater with a column template.
Then I'd use the repeater's ItemDataBound event to examine the data and set
controls in the current row visible/hidden as necessary.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Gummy

Thank you for the information.

Now, how do I reference each row? Here is the code I am using:

Private Sub dlYesNo_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlYesNo.ItemDataBound
Dim ds As DataSet
Dim dr As DataRow
Dim strSQL As String
Dim rd As New ClassSurvey.DataTransfer

strSQL = String.Format("Select QuesID, Question, QuestionType from
tblQuestions;")

'Get a DataSet from the SQL and the Connection String
ds = rd.GetDataSet(strSQL, rd.CONN_STR)

For Each dr In ds.Tables(0).Rows
Debug.WriteLine(dr.Item("QuesID"))

If CStr(dr.Item("QuesID")) = "1" Or CStr(dr.Item("QuesID")) = "4" Then
e.Item.FindControl("rblQues3").Visible = False
Else
e.Item.FindControl("rblQues3").Visible = True
End If

Next

I know this isn't pretty code, but it make that RadioListBox invisible for
all the rows.

What is the best way to approach this?

Thanks again for all your help.



message Gummy,
 
S

S. Justin Gengo

The repeater has an overridable ItemDataboundEvent that you may use to break
into each row as the data is being bound to it. You can access each row as
an item and refer to the controls in the template.

Inside it would look something like this:

e.Item(0).Controls(0).Visible = false;

Where the first zero is first column in the zero based column and the second
zero is the first control in the zero based index of controls in that
column.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top