473,320 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2040
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 ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.