473,761 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 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
Nov 19 '05 #1
2 2066
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_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
|

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1547
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 one of the radio buttons <asp:datalist id="studentList1" runat="server"><ItemTemplate><%# DataBinder.Eval(Container.DataItem, "cQtext") %><asp:RadioButton id="Radio1" Text="0 (Καθόλου)" Checked="False" GroupName='<%#...
0
1651
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 know the seleceted row of the datalist. radiobutton checkchanged event is not firing.
1
1577
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 to set the Radio button to the image's current status. Does anyone know how I can do this? Thanks in advance.
0
2122
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 selected if there ends up being more than one in the list. However, it's not working. Even though I have set the Group name, I can select every radio button that gets displayed. Anyone know what I need to do to fix this? Thanks in advance!
3
5949
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 to select a default item so when the user clicks one of the radio buttons, it needs to clear the checked property from the rest. This is default behavior for the radio button, but it doesn't work when it is embedded into a datalist. I have tried...
2
2724
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 lable so that all the radio buttons line up on top of each other? Right now they are flush next to each other even if there is only 5 characters or 20 characters. I have the datalist set as:
3
5407
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. Also I want to get the checked value from my code behind. I have tried with the following code. Each time I click the button to find the value of the radio button, getting an error "Object reference is not set". HTML ====
16
12146
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 radio button to be preselected in this datalist how can i do that doing something like this but this gives error "The type or namespace name 'rdbtn' could not be found (are you missing a using directive or an assembly reference?)" as its in datalist
5
4769
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 name="txtPass" value='<%#DataBinder.Eval(Container.DataItem,"Passwd")%>'></td> <td width="45%" align="left">
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.