468,247 Members | 1,276 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

datalist radio group

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
Nov 19 '05 #1
2 1894
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."

Nov 19 '05 #2
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=?=" <cm****@nospam.nospam>
| Subject: datalist radio group
| Date: Mon, 3 Oct 2005 09:55:01 -0700
| Lines: 64
| Message-ID: <13**********************************@microsoft.co m>
| 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
|

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by manu_srinivasa | last post: by
1 post views Thread by pierre.basson | last post: by
reply views Thread by David Hearn | last post: by
2 posts views Thread by tshad | last post: by
3 posts views Thread by Sourav Dutta Gupta | last post: by
16 posts views Thread by Vikas Kumar | last post: by
5 posts views Thread by Vikas Kumar | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.