datalist and radio button group

C

cindy

When my datalist loads I am trying to make the checked value in a radio
button group reflect which value is stored in the data and then fire and
event when the CheckChanged event fires.

private void InitializeComponent()
{
if(!Page.IsPostBack){
this.ds = new System.Data.DataSet();
this.daListHW.DataSource=ds;
this.daListHW.DataBind();}

The data has a field "HWDesc", it can be "Toshiba" or "NEMA" or null
When the datalist loads I can have 2 controls

<asp:RadioButton id="RadioToshiba" Text='Toshiba' runat="server"
TextAlign="right" GroupName="hwdesc" />
<asp:RadioButton id="RadioNEMA" Text='NEMA' runat="server"
TextAlign="right" GroupName="hwdesc" />

I created in Page Load

daListHW.ItemCreated +=new DataListItemEventHandler(daListHW_ItemCreated);

the handler is

private void daListHW_ItemCreated(object sender, DataListItemEventArgs e)
{
DataRowView drv = (DataRowView)(e.Item.DataItem);
string HWmodel = drv.Row["HWDesc"].ToString();
if (HWmodel == "Toshiba")
{
this.RadioToshiba.Checked=true;
}
if (HWmodel == "NEMA")
{
this.RadioNema.Checked=true;
}
}

When it runs I get

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 317: {
Line 318: DataRowView drv = (DataRowView)(e.Item.DataItem);
Line 319: string HWmodel = drv.Row["HWDesc"].ToString();
Line 320: if (HWmodel == "Toshiba")
Line 321: {


If I set the Text value of the radio button to
<asp:RadioButton id="RadioNEMA" Text='<%#
DataBinder.Eval(Container.DataItem, "HWDesc") %>' runat="server"
TextAlign="right" GroupName="hwdesc" />

The text for the model on the row is "NEMA" so there is something but I am
not getting to it at the right time?
this is newbie question sorry
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top