472,958 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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 2018
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: darkelf | last post by:
Hello I have a aspx page with a two datalist controls. Inside them I have some radio buttons that are created with data binding for the user to choose. It displays a question and user has to choose...
0
by: manu_srinivasa | last post by:
:( Here is my design, we have user control placed in a aspx page. within user control, i am having datalist, within datalist i am placing radio button. On click of radio button, i need to...
1
by: pierre.basson | last post by:
Hi, I have a DataList that contains an image and 3 radio buttons. The radio buttons are used to change the status of the image i.e. Approved, Suspended and Deleted. When the form loads, I want...
0
by: David Hearn | last post by:
I have a datalist with an ItemTemplate set up. In the item template, I have a radio button. I have set the groupname on the radio button so that you should only be able to have one radio button...
3
by: David Hearn | last post by:
I have a datalist that I have inserted a radio button into. The datalist populates with a list of items and each one has a radio button next to it. I need to use the radio button to allow the user...
2
by: tshad | last post by:
I have a Datalist that will display 4 columns of data. I am not using a table format just labels to display a radio button and label for the radio button. Is there a way to set a size for the...
3
by: Sourav Dutta Gupta | last post by:
I am having some problem regarding radiobutton inside a datalist. I want to have a radiobutton on each row of my datalist. I want to check a particular button, all the other would remain unchecked....
16
by: Vikas Kumar | last post by:
i am selectin some data from database and through reader showing it in datalist as above now for radio buttons i have single column which returns 1,2,3 and according to that i want one of above...
5
by: Vikas Kumar | last post by:
i had coded like this <ItemTemplate> <table width="100%"> <tr width="100%"> <td width="25%"><%#DataBinder.Eval(Container.DataItem,"FName")%></td> <td width="25%"><input type=text ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.