datalist radio group

G

Guest

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
 
K

Kevin Yu [MSFT]

Hi

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
S

Steven Cheng[MSFT]

Hi Cindy,

From the code snippet you provided, you're accessing the DataRowView's
binded DataItem in the ItemCreated event, base on my understanding ,in the
ItemCreated event, there has no DataItem in the property, so you'll get the
NullReference exception.

==============
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;
}
}
=================

Generally for accessing the binded data and customzie the inner control's
properties, we need to use the DataList/DataGrid's ItemDataBound event ,
this event will be fired for each RowItem's databinding after we call
DataList.DataBind. You can try use this event instead to see whether you
can correctly get the datarecord's value.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: datalist radio group
| thread-index: AcXIOzHkk1Wg7jTURXuP2QE8/uKCpQ==
| X-WBNR-Posting-Host: 71.136.160.120
| From: "=?Utf-8?B?Y2luZHk=?=" <[email protected]>
| Subject: datalist radio group
| Date: Mon, 3 Oct 2005 09:55:01 -0700
| Lines: 64
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:128694
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| 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
| --
| cindy
|
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top