Solved

How to use a DataSet as a DataSource for a RadioButtonList

Posted on 2006-07-18
12
515 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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