Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to use a DataSet as a DataSource for a RadioButtonList

Posted on 2006-07-18
12
Medium Priority
?
528 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
Industry Leaders: 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

604 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