Data Binding a Bit Column to RadioButtonList

M

Michael

Hi,

This should be fairly simple, but it is driving me nuts. First off I have a
table in SQL Server, with a column of type "bit". This is meant to store a
answer to a Yes/No question.

I'm trying to display this stored value in SQL Server in a RadioButtonList
in ASP.NET. I have the value stored in ado.net DataSet, which I can
reference just like this
myDataSet.Tables(0).Rows(0)("my_bit_column")

My problem is, I don't know how to bind this result, to the RadioButtonList.
I would believe I need to use the RadioButtonList's methods FindByText or
FindByValue methods, and I've tried something like this...

RadioButtonList1.Items.FindByValue(CStr(myDataSet.Tables(0).Rows(0)("my_bit_
column"))).Selected = True

But I get this beautiful error.."System.NullReferenceException: Object
reference not set to an instance of an object."

Can anyone help me out, it seems I'm making this more complicated that it
has to be!

Thanks!
--Michael
 
C

Craig Deelsnyder

Michael said:
RadioButtonList1.Items.FindByValue(CStr(myDataSet.Tables(0).Rows(0)("my_bit_
column"))).Selected = True

But I get this beautiful error.."System.NullReferenceException: Object
reference not set to an instance of an object."

Can anyone help me out, it seems I'm making this more complicated that it
has to be!

Thanks!
--Michael

Apparently it can't find that value in the FindByValue. Are you sure
you do a DataBind before trying to do this line? Otherwise your items
in the list aren't created yet....
 

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

Top