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_ItemCr eated(object sender, DataListItemEve ntArgs e)
{
DataRowView drv = (DataRowView)(e .Item.DataItem) ;
string HWmodel = drv.Row["HWDesc"].ToString();
if (HWmodel == "Toshiba")
{
this.RadioToshi ba.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.DataBi nd. 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: AcXIOzHkk1Wg7jT URXuP2QE8/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************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GXA03.phx.gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1286 94
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 InitializeCompo nent()
| {
| if(!Page.IsPost Back){
| this.ds = new System.Data.Dat aSet();
| this.daListHW.D ataSource=ds;
| this.daListHW.D ataBind();}
|
| The data has a field "HWDesc", it can be "Toshiba" or "NEMA" or null
| When the datalist loads I can have 2 controls
|
| <asp:RadioButto n id="RadioToshib a" Text='Toshiba' runat="server"
| TextAlign="righ t" GroupName="hwde sc" />
| <asp:RadioButto n id="RadioNEMA" Text='NEMA' runat="server"
| TextAlign="righ t" GroupName="hwde sc" />
|
| I created in Page Load
|
| daListHW.ItemCr eated +=new
DataListItemEve ntHandler(daLis tHW_ItemCreated );
|
| the handler is
|
| private void daListHW_ItemCr eated(object sender, DataListItemEve ntArgs e)
| {
| DataRowView drv = (DataRowView)(e .Item.DataItem) ;
| string HWmodel = drv.Row["HWDesc"].ToString();
| if (HWmodel == "Toshiba")
| {
| this.RadioToshi ba.Checked=true ;
| }
| if (HWmodel == "NEMA")
| {
| this.RadioNema. Checked=true;
| }
| }
|
| When it runs I get
|
| Exception Details: System.NullRefe renceException: 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:RadioButto n id="RadioNEMA" Text='<%#
| DataBinder.Eval (Container.Data Item, "HWDesc") %>' runat="server"
| TextAlign="righ t" GroupName="hwde sc" />
|
| 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
|