Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Datalist and RadioButton

Reply
Thread Tools

Datalist and RadioButton

 
 
Rob Risner
Guest
Posts: n/a
 
      04-20-2004
Is there a way to use a RadioButton web control in a datalist template
column without the button getting a unique name? It doesn't allow a single
radio button to be clicked.

Thanks,
Rob


 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      04-20-2004
Radiobuttonlists implement inamingcontainer which forces unique id's. What
are you trying to do? Maybe there is a workaround

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Rob Risner" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Is there a way to use a RadioButton web control in a datalist template
> column without the button getting a unique name? It doesn't allow a single
> radio button to be clicked.
>
> Thanks,
> Rob
>



 
Reply With Quote
 
 
 
 
Rob Risner
Guest
Posts: n/a
 
      04-20-2004
I am trying to display a list of images and allow the user to click on a
radio button to select one. I thought about the Radiobuttonlist but that
seems to want a Datatextfield to show one item from the database.

Thanks for the quick reply,
Rob

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%23w3$(E-Mail Removed)...
> Radiobuttonlists implement inamingcontainer which forces unique id's. What
> are you trying to do? Maybe there is a workaround
>
> --
> Regards,
> Alvin Bruney [ASP.NET MVP]
> Got tidbits? Get it here...
> http://tinyurl.com/27cok
> "Rob Risner" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Is there a way to use a RadioButton web control in a datalist template
>> column without the button getting a unique name? It doesn't allow a
>> single radio button to be clicked.
>>
>> Thanks,
>> Rob
>>

>
>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-20-2004
Hi Rob,

Based on my understanding, you nested RadioButton in the DataList control,
and you want to handle the CheckedChanged event for different RadioButton.

Suppose you are doing like this:
<aspataList id="DataList1" runat="server">
<ItemTemplate>
<asp:RadioButton Runat="server" ID="rb"></asp:RadioButton>
</ItemTemplate>
</aspataList>

To handle the RadioButton's CheckedChanged event for each row, you should
hook into DataList.ItemCreated event, and add the event handler for it. Do
like this:

private void DataList1_ItemCreated(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item)
{
RadioButton rb=e.Item.FindControl("rb") as RadioButton;
rb.CheckedChanged+=new EventHandler(rb_CheckedChanged);
}
}

private void rb_CheckedChanged(object sender, EventArgs e)
{
}

Then, in the rb_CheckedChanged, you can do your program logic.

===============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-22-2004
Hi Rob,

Does my reply make sense to you? Do you still have any concern on this
issue?

Please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Rob Risner
Guest
Posts: n/a
 
      04-22-2004
I tried your method and could not get it to work. I've stepped through and
it's adding a new event handler to the rb.CheckedChanged but rb_CheckChanged
is not being called when the radio button is being click during a post back.
This also does not solve the problem with the user being able to click
multiple radio buttons and their name uniquness. I've worked around this by
simply using a radio button list instead.

Thanks,
Rob

""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Rob,
>
> Based on my understanding, you nested RadioButton in the DataList control,
> and you want to handle the CheckedChanged event for different RadioButton.
>
> Suppose you are doing like this:
> <aspataList id="DataList1" runat="server">
> <ItemTemplate>
> <asp:RadioButton Runat="server" ID="rb"></asp:RadioButton>
> </ItemTemplate>
> </aspataList>
>
> To handle the RadioButton's CheckedChanged event for each row, you should
> hook into DataList.ItemCreated event, and add the event handler for it. Do
> like this:
>
> private void DataList1_ItemCreated(object sender,
> System.Web.UI.WebControls.DataListItemEventArgs e)
> {
> if(e.Item.ItemType==ListItemType.Item)
> {
> RadioButton rb=e.Item.FindControl("rb") as RadioButton;
> rb.CheckedChanged+=new EventHandler(rb_CheckedChanged);
> }
> }
>
> private void rb_CheckedChanged(object sender, EventArgs e)
> {
> }
>
> Then, in the rb_CheckedChanged, you can do your program logic.
>
> ===============================================
> Please apply my suggestion above and let me know if it helps resolve your
> problem.
>
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-22-2004
Hi Rob,

Thanks very much for your feedback.

For your RadioButton event does not fire problem, it is a common issue.
Normally, it is because you did not determine the postback, and re-bind
your datagrid every postback time. Like this:

private void Page_Load(object sender, System.EventArgs e)
{
DataSet ds=new DataSet ();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=" );
adapter.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}

Through this way, your datagrid's child controls(Such as RadioButton) will
be re-created every postback, its status will be re-freshed every time, so
its event will not fire. Instead, you should only bind the DataGrid at the
first time, like this:

private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
DataSet ds=new DataSet ();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=" );
adapter.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
}

Through this way, the event should fire for you.

If this is not your problem, please pasted some code snippet to reproduce
your problem, I will figure out the problem for you.
========================================

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Rob Risner
Guest
Posts: n/a
 
      04-22-2004
There is still the problem with unique RadioButtons.

The datalist changes the names to
DataList1__ctl0_rb
DataList1__ctl1_rb
Etc...

This allows for mulitple RadioButtons to be checked.

""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
newsi$(E-Mail Removed)...
> Hi Rob,
>
> Thanks very much for your feedback.
>
> For your RadioButton event does not fire problem, it is a common issue.
> Normally, it is because you did not determine the postback, and re-bind
> your datagrid every postback time. Like this:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> DataSet ds=new DataSet ();
> SqlDataAdapter adapter=new SqlDataAdapter("select * from
> jobs","server=localhost;database=pubs;uid=sa;pwd=" );
> adapter.Fill(ds);
> DataGrid1.DataSource=ds;
> DataGrid1.DataBind();
> }
>
> Through this way, your datagrid's child controls(Such as RadioButton) will
> be re-created every postback, its status will be re-freshed every time, so
> its event will not fire. Instead, you should only bind the DataGrid at the
> first time, like this:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> if(!this.IsPostBack)
> {
> DataSet ds=new DataSet ();
> SqlDataAdapter adapter=new SqlDataAdapter("select * from
> jobs","server=localhost;database=pubs;uid=sa;pwd=" );
> adapter.Fill(ds);
> DataGrid1.DataSource=ds;
> DataGrid1.DataBind();
> }
> }
>
> Through this way, the event should fire for you.
>
> If this is not your problem, please pasted some code snippet to reproduce
> your problem, I will figure out the problem for you.
> ========================================
>
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-22-2004
Hi Rob,

Thanks very much for your feedback.

Oh, yes, in Asp.net Repeater controls, you can not make them Mutually
Exclusive, this is a known issue, please refer to:
"BUG: Radio Buttons Are Not Mutually Exclusive When Used in a Repeater
Server Control"
http://support.microsoft.com/default...b;en-us;316495

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-26-2004
Hi Rob,

Does my reply make sense to you? Do you still have any concern on this
issue?

Please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Radiobutton inside datalist ensingg ASP .Net 0 09-17-2006 09:36 AM
How to check a html-radiobutton inside a datalist ensingg ASP .Net 0 09-15-2006 01:02 PM
Selecting item with radiobutton in datalist Gert ASP .Net 0 08-02-2006 08:09 AM
DataList with RadioButtons + Images: How to click on the images to activate the radiobutton? Luis Esteban Valencia Muņoz ASP .Net 0 06-03-2005 03:22 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM



Advertisments