Solved

How to use a DataSet as a DataSource for a RadioButtonList

Posted on 2006-07-18
12
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 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