473,795 Members | 2,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fire event handler for each radiobutton

I have a Asp.net table control that I dynamically add rows from a SQL
database. Inside the table, I add radiobuttons and they all have
different ID numbers according to BindChain()

Looking In BindChain() Sub for the line:
AddHandler Rb.CheckedChang ed, AddressOf BindAssembly_Cl ick

I can't get the radiobutton to attach the same BindAssembly_Cl ick()
event for each radiobutton. In fact it is attaching an event with the
ID number and the page gets posted when I click on it. It's weird. I
don't know where it's getting that from. I am desperate, Please help
me.

Table HTML code generated
<table id="Tbchain" border="0"
style="border-width:1px;borde r-style:solid;">

<tr>

<td><input id="Radio0" type="radio" name="MySel" value="Radio0"
checked="checke d" onclick="__doPo stBack('Radio0' ,'')"
language="javas cript" /><label
for="Radio0">C1 88</label></td><td></td><td><img
src=chain_image s/C188.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio1" type="radio" name="MySel" value="Radio1"
onclick="__doPo stBack('Radio1' ,'')" language="javas cript" /><label
for="Radio1">D6 67</label></td><td></td><td><img
src=chain_image s/D667.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio2" type="radio" name="MySel" value="Radio2"
onclick="__doPo stBack('Radio2' ,'')" language="javas cript" /><label
for="Radio2">D8 1X</label></td><td></td><td><img
src=chain_image s/D81X.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio3" type="radio" name="MySel" value="Radio3"
onclick="__doPo stBack('Radio3' ,'')" language="javas cript" /><label
for="Radio3">D8 8K</label></td><td></td><td><img
src=chain_image s/D88K.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio4" type="radio" name="MySel" value="Radio4"
onclick="__doPo stBack('Radio4' ,'')" language="javas cript" /><label
for="Radio4">SC 78</label></td><td></td><td><img
src=chain_image s/SC78.gif></td><td>&nbsp;</td>

</tr>

</table>

I need to get this type of result:
<table id="Tbchain" border="0"
style="border-width:1px;borde r-style:solid;">

<tr>

<td><input id="Radio0" type="radio" name="MySel" value="Radio0"
checked="checke d" onclick="__doPo stBack('BindAss embly_Click','' )"
language="javas cript" /><label
for="Radio0">C1 88</label></td><td></td><td><img
src=chain_image s/C188.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio1" type="radio" name="MySel" value="Radio1"
onclick="__doPo stBack('BindAss embly_Click','' )" language="javas cript"
/><label for="Radio1">D6 67</label></td><td></td><td><img
src=chain_image s/D667.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio2" type="radio" name="MySel" value="Radio2"
onclick="__doPo stBack('BindAss embly_Click','' )" language="javas cript"
/><label for="Radio2">D8 1X</label></td><td></td><td><img
src=chain_image s/D81X.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio3" type="radio" name="MySel" value="Radio3"
onclick="__doPo stBack('BindAss embly_Click','' )" language="javas cript"
/><label for="Radio3">D8 8K</label></td><td></td><td><img
src=chain_image s/D88K.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio4" type="radio" name="MySel" value="Radio4"
onclick="__doPo stBack('BindAss embly_Click','' )" language="javas cript"
/><label for="Radio4">SC 78</label></td><td></td><td><img
src=chain_image s/SC78.gif></td><td>&nbsp;</td>

</tr>

</table>

Source Code
<%@ Page Language="VB" ContentType="te xt/html"
ResponseEncodin g="iso-8859-1" %>

<%@ import Namespace="Syst em.Web.UI.WebCo ntrols" %>

<%@ import Namespace="Syst em.Net" %>

<%@ import Namespace="Syst em.Data.SqlClie nt" %>

<%@ import Namespace="Syst em.Data" %>

<script language="VB" Debug="true" runat="server">

Public Const DB_CONN_STRING = "my connection"

Public cChainID as Integer

'Protected WithEvents optModify As
System.Web.UI.W ebControls.Radi oButton

Sub Page_Load(src As Object, e As EventArgs)

if not IsPostBack Then

BindManufacture r()

BindConveyorTyp e()

BindChain()

BindAssembly()

End if

End Sub

Sub BindManufacture r()

Dim strConn=DB_CONN _STRING

Dim mycn As SqlConnection = new SqlConnection(s trConn)

Dim SQL As String = "SELECT manufacturer FROM Sn_Rollers GROUP BY
manufacturer"

Dim myda As SqlDataAdapter = new SqlDataAdapter (SQL, mycn)

Dim ds As DataSet = new DataSet()

myda.Fill (ds,"Table1")

manufacturer.Da taTextField="ma nufacturer"

manufacturer.Da taValueField="m anufacturer"

manufacturer.Da taSource=ds

manufacturer.Da taBind()

End Sub

Sub BindConveyorTyp e()

Dim strConn=DB_CONN _STRING

Dim mycn As SqlConnection = new SqlConnection(s trConn)

Dim manuf As String = manufacturer.se lecteditem.valu e

Dim SQL As String = "SELECT manufacturer, convtp FROM Sn_Rollers
WHERE (manufacturer = '"+manuf+"') GROUP BY manufacturer, convtp"

Dim myda As SqlDataAdapter = new SqlDataAdapter (SQL, mycn)

Dim ds As DataSet = new DataSet()

myda.Fill (ds,"Table2")

convtype.DataTe xtField="convtp "

convtype.DataVa lueField="convt p"

convtype.DataSo urce=ds

convtype.DataBi nd()

BindChain()

End Sub

Sub BindChain()

Dim strConn=DB_CONN _STRING

Dim mycn As SqlConnection = new SqlConnection(s trConn)

Dim Smanufacturer As String = manufacturer.se lecteditem.valu e

Dim Sconvtype As String = convtype.select editem.value

Dim SQL As String = "SELECT manufacturer, convtp, chain FROM
Sn_Rollers WHERE (manufacturer = '"+Smanufacture r+"' AND convtp =
'"+Sconvtype+"' ) GROUP BY manufacturer, convtp, chain"

Response.Write( "CHAIN <br>"+ SQL + "<br><br>" )

Dim myda As SqlDataAdapter = new SqlDataAdapter (SQL, mycn)

Dim ds As DataSet = new DataSet()

myda.Fill (ds,"Table3")

'chain.DataSour ce=ds

'chain.DataBind ()

Dim i As integer

For i = 0 To ds.Tables("Tabl e3").Rows.Cou nt - 1

Dim tRow As New TableRow()

Dim tCell_1 As New TableCell()

Dim tCell_2 As New TableCell()

Dim tCell_3 As New TableCell()

Dim tCell_4 As New TableCell()

Rb = New RadioButton()

cChainID=i

Rb.ID = "Radio" + i.ToString()

Rb.Text = ds.Tables("Tabl e3").Rows(i).It em(2).ToString( )

Rb.GroupName="M ySel"

************ Here is the problem
*************** *************** ********

AddHandler Rb.CheckedChang ed, AddressOf BindAssembly_Cl ick

' It is not linking the same sub event BindAssembly_Cl ick() for each
radiobutton. Instead, it is adding an event with the ID name from
Rb.ID="Radio"+ i.ToString()

*************** ************ || *************** *************** ********

Rb.AutoPostBack = True

'Rb.Checked = True

tCell_1.Control s.Add(Rb)

tRow.Cells.Add( tCell_1)

tRow.Cells.Add( tCell_2)

Tbchain.Rows.Ad d(tRow)

tCell_3.Text="< img
src=chain_image s/"+Replace(ds.Ta bles("Table3"). Rows(i).Item(2) .ToString(),"
","") +".gif>"

tCell_4.Text="& nbsp;"

tRow.Cells.Add( tCell_3)

tRow.Cells.Add( tCell_4)

Tbchain.Rows.Ad d(tRow)

next

End Sub

function LoopTextBoxes(B yVal parent As Control) As String

Dim c As Control

Dim finish As Boolean = false

For Each c In parent.Controls

If c.GetType() Is GetType(RadioBu tton) Then

if Ctype(c, RadioButton).Ch ecked=True then

LoopTextBoxes=C type(c, RadioButton).Te xt

exit function

end if

End If

If (c.HasControls) Then

LoopTextBoxes(c )

End If

Next

End function

Sub BindAssembly()

Dim strConn=DB_CONN _STRING

Dim mycn As SqlConnection = new SqlConnection(s trConn)

Dim Smanufacturer As String = manufacturer.se lecteditem.valu e

Dim Sconvtype As String = convtype.select editem.value

Dim Schain As string

Schain = LoopTextBoxes(M e)

Dim SQL As String = "SELECT manufacturer, convtp, chain, assembly
FROM Sn_Rollers WHERE (manufacturer = '"+Smanufacture r+"' AND convtp =
'"+Sconvtype +"' AND chain = '"+Schain +"') GROUP BY manufacturer,
convtp, chain, assembly"

Response.write( SQL)

Dim myda As SqlDataAdapter = new SqlDataAdapter (SQL, mycn)

Dim ds As DataSet = new DataSet()

myda.Fill (ds,"Table4")

Dpassembly.Data TextField="asse mbly"

Dpassembly.Data ValueField="ass embly"

Dpassembly.Data Source=ds

Dpassembly.Data Bind()

End Sub

Sub BindConveyorTyp e_Click(sender As Object, e As EventArgs)

BindConveyorTyp e()

End Sub

Sub BindChain_Click (sender As Object, e As EventArgs)

BindChain()

End Sub

Sub BindAssembly_Cl ick(sender As Object, e As EventArgs)

BindAssembly()

End Sub

</script>

Thanks

Rod
Jul 19 '05 #1
0 4139

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

Similar topics

3
7286
by: dave | last post by:
I have half a dozen web form radio buttons on a web form. Each of them is set to postback=true. However, if for instance radiobutton1 is already selected and the user selects it again, it performs a postback. I only want to do a postback if the value of the radiobutton is changed. What is the best method to accomplish this? thx dave
7
2456
by: Gordon Smith | last post by:
I have four (4) ASP.NET Web applications/Web sites on a IIS/6 - Windows Server 2003 production server. 3 of them work fine. I just installed the 4th one and it's Application_Start event is not firing. I have double-checked everything (and rechecked) and I haven't found anything that would explain why the Application is not starting. Here is what I have done so far to troubleshoot this: In IIS Manager I have ensured that there is a...
6
2208
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
2
1506
by: Brano | last post by:
HI all, I have two radioButtons on my form. They both have autopostback = true and they are both in the same group. They both have event handlers for CheckedChanged event. My problem is ont of them fires ok the other one doesn't at all here is the code for them: I have tried to delete them drag them from the toolbox again and restart VS.NET none helped.
3
6623
by: LCAdeveloper | last post by:
Help! A trawl through the archives couldn't shed any light on this, so is there a way to handle DoubleClick events for RadioButtons in vb.NET? I'm recoding a VB4 application, which used the double-click event on some SSOption buttons and would like to duplicate this behaviour (for existing users) in the vb.NET version. Using the cursor arrows to navigate through radiobuttons contained in a groupbox inititates the click event for the...
0
299
by: rodrigo | last post by:
I have a Asp.net table control that I dynamically add rows from a SQL database. Inside the table, I add radiobuttons and they all have different ID numbers according to BindChain() Looking In BindChain() Sub for the line: AddHandler Rb.CheckedChanged, AddressOf BindAssembly_Click
19
4759
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
2
3930
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite well, so at times it is tempting just to port parts of it over mostly as-is. In fact, one MSDN article I read suggested using straight HTML wherever possible to make the app more efficient and less resource demanding. On one page there are 2...
5
2093
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, On a usercontrol I've put a set of radiobuttons within a groupbox. These radiobuttons have visual style enables, i.e. they turn orange when hovering over them and green when pushed. Normally I put my updation of data shown in the controls on the usercontrol in the Paint event handler of the usercontrol. When it comes to the radiobuttons, a paint event for the usercontrol is fired whenever hovering over the radiobuttons, making...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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
10001
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
9042
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
7540
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
5437
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
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.