Solved

How to use a DataSet as a DataSource for a RadioButtonList

Posted on 2006-07-18
12
508 Views
Last Modified: 2008-01-09
Hi,

I'm using ASP.NET 1.1.

I have a DataSet. When I use GetXml to look at its structure, it look like this:

<NewDataSet>
  <Table>
    <Answers>Answer 1, Question 1, Mod 1</Answers>
    <AnswersID>1</AnswersID>
    <QuestionsID>1</QuestionsID>
    <QuestionsID1>1</QuestionsID1>
    <ModuleID>1</ModuleID>
    <ModuleID1>1</ModuleID1>
  </Table>
  <Table>
    <Answers>Answer 2, Question 1, Mod 1</Answers>
    <AnswersID>2</AnswersID>
    <QuestionsID>1</QuestionsID>
    <QuestionsID1>1</QuestionsID1>
    <ModuleID>1</ModuleID>
    <ModuleID1>1</ModuleID1>
  </Table>
  <Table>
    <Answers>Answer 3, Question 1, Mod 1</Answers>
    <AnswersID>3</AnswersID>
    <QuestionsID>1</QuestionsID>
    <QuestionsID1>1</QuestionsID1>
    <ModuleID>1</ModuleID>
    <ModuleID1>1</ModuleID1>
  </Table>
  <Table>
    <Answers>Answer 4, Question 1, Mod 1</Answers>
    <AnswersID>4</AnswersID>
    <QuestionsID>1</QuestionsID>
    <QuestionsID1>1</QuestionsID1>
    <ModuleID>1</ModuleID>
    <ModuleID1>1</ModuleID1>
  </Table>
</NewDataSet>


How can I specify that I want to use the content of <Answers>?  I have tried a couple of things, but no luck so far.
Thanks,
Jens
0
Comment
Question by:tmccrank
  • 7
  • 3
  • 2
12 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17133559
Here is an example with VB.NET:

Me.RadioButtonList1.DataSource = Me.DataSet1.Tables("Answers")
Me.RadioButtonList1.DataTextField = "Answers"
Me.RadioButtonList1.DataValueField = "AnswersID"
Me.RadioButtonList1.DataBind()

Bob
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17133654
I think you should consider custom databinding classes. Your class can search the database and depending on the result return the collection to be bind in radio button control:

Implementing Custom Data Bindable Classes: CollectionBase
http://www.ondotnet.com/pub/a/dotnet/2003/06/02/collectionbase.html

--Nauman.
0
 

Author Comment

by:tmccrank
ID: 17134110
Thanks Bob, but no luck.

FWIW, when I typed the first line:

Me.rblAnswers.DataSource = Me.dsAnswers.Tables("Answers")

...the intellisence wasn't bringing up dsAnswers.  However, dsAnswers is definitely recognized because dsAnswers.Tables("Answers") doesn't return a build error.

Jens
0
 

Author Comment

by:tmccrank
ID: 17134122
Nauman,

Sounds interesting.  I'd like to exhaust the possibilities the way Bob has gone first, I'm more familiar with how they work.

thanks,
Jens
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17134277
There is one thing that is kinda confusing:

<Answers>Answer 1, Question 1, Mod 1</Answers>

Does it has three answer options or all the items are counted as one answer?

-Nauman.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17135337
Only use Me, if the DataSet is defined at module-level.  If it is defined locally within a method, remove it.

Bob
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:tmccrank
ID: 17138994
Bob,

While debugging, rblAnswers.DataSource = dsAnswers.Tables("Answers") is coming up as "Nothing".

I tried a couple of different things, including:

rblAnswers.DataSource = dsAnswers.Tables(0).Columns(0).ToString

Each letter of the word 'Answers' simply becomes the content of a radio button.   Any other idea??  Thanks


Nauman, I just did that for my own reference; it helps me to check if the DB and databindings are working properly.  The contents will be replaced with 'real' answers once I have this stuff figured out.
0
 

Author Comment

by:tmccrank
ID: 17139004
Nauman, sorry, to answer your question, it all counts as one answer.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17139017
If there is a post-back, and you are not persisting the DataSet, then it will be lost.  Also, I guessed at the name of the table 'Answers'--is that the correct name for the table?

Bob
0
 

Author Comment

by:tmccrank
ID: 17139252
I looks to me like the name of the table is "Table".  "Answers" is the first column in "Table".  With that in mind, I tried this:

rblAnswers.DataSource = dsAnswers.Tables("Table").Columns("Answers").ToString()

I got the same result as with rblAnswers.DataSource = dsAnswers.Tables(0).Columns(0).ToString, which makes sense seeing as I just used the names of the columns instead of the index.

The DataSet seems to be persisting, if only because radio buttons are populated with A, n, s, w, e, r
0
 

Author Comment

by:tmccrank
ID: 17139614
Bob,

OK, with your help I'm now one step closer to my goal, thanks.  Here's what I have:

                rblAnswers.DataSource = dsAnswers.Tables("Table")
                rblAnswers.DataTextField = "Answers"
                rblAnswers.DataValueField = "AnswersID"

The good news is, the RadioButtonList under each Question is being populated with the content of each <Answers> column.  
BUT each RadioButtonList has all 5 <Answers> for all 5 <Questions> that I have in my testing Database.  This means that each RBL has 25 <Answers>, not 5 <Answers>.

But that's another question that I may put out there.  Thanks again for your help on this one.

Jens
0
 

Author Comment

by:tmccrank
ID: 17139625
It was the fact that I was putting the name of the column where the name of the Table should be.
Thx.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now