473,385 Members | 1,312 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,385 software developers and data experts.

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.CheckedChanged, AddressOf BindAssembly_Click

I can't get the radiobutton to attach the same BindAssembly_Click()
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;border-style:solid;">

<tr>

<td><input id="Radio0" type="radio" name="MySel" value="Radio0"
checked="checked" onclick="__doPostBack('Radio0','')"
language="javascript" /><label
for="Radio0">C188</label></td><td></td><td><img
src=chain_images/C188.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio1" type="radio" name="MySel" value="Radio1"
onclick="__doPostBack('Radio1','')" language="javascript" /><label
for="Radio1">D667</label></td><td></td><td><img
src=chain_images/D667.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio2" type="radio" name="MySel" value="Radio2"
onclick="__doPostBack('Radio2','')" language="javascript" /><label
for="Radio2">D81X</label></td><td></td><td><img
src=chain_images/D81X.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio3" type="radio" name="MySel" value="Radio3"
onclick="__doPostBack('Radio3','')" language="javascript" /><label
for="Radio3">D88K</label></td><td></td><td><img
src=chain_images/D88K.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio4" type="radio" name="MySel" value="Radio4"
onclick="__doPostBack('Radio4','')" language="javascript" /><label
for="Radio4">SC78</label></td><td></td><td><img
src=chain_images/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;border-style:solid;">

<tr>

<td><input id="Radio0" type="radio" name="MySel" value="Radio0"
checked="checked" onclick="__doPostBack('BindAssembly_Click','')"
language="javascript" /><label
for="Radio0">C188</label></td><td></td><td><img
src=chain_images/C188.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio1" type="radio" name="MySel" value="Radio1"
onclick="__doPostBack('BindAssembly_Click','')" language="javascript"
/><label for="Radio1">D667</label></td><td></td><td><img
src=chain_images/D667.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio2" type="radio" name="MySel" value="Radio2"
onclick="__doPostBack('BindAssembly_Click','')" language="javascript"
/><label for="Radio2">D81X</label></td><td></td><td><img
src=chain_images/D81X.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio3" type="radio" name="MySel" value="Radio3"
onclick="__doPostBack('BindAssembly_Click','')" language="javascript"
/><label for="Radio3">D88K</label></td><td></td><td><img
src=chain_images/D88K.gif></td><td>&nbsp;</td>

</tr><tr>

<td><input id="Radio4" type="radio" name="MySel" value="Radio4"
onclick="__doPostBack('BindAssembly_Click','')" language="javascript"
/><label for="Radio4">SC78</label></td><td></td><td><img
src=chain_images/SC78.gif></td><td>&nbsp;</td>

</tr>

</table>

Source Code
<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>

<%@ import Namespace="System.Web.UI.WebControls" %>

<%@ import Namespace="System.Net" %>

<%@ import Namespace="System.Data.SqlClient" %>

<%@ import Namespace="System.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.WebControls.RadioButton

Sub Page_Load(src As Object, e As EventArgs)

if not IsPostBack Then

BindManufacturer()

BindConveyorType()

BindChain()

BindAssembly()

End if

End Sub

Sub BindManufacturer()

Dim strConn=DB_CONN_STRING

Dim mycn As SqlConnection = new SqlConnection(strConn)

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.DataTextField="manufacturer"

manufacturer.DataValueField="manufacturer"

manufacturer.DataSource=ds

manufacturer.DataBind()

End Sub

Sub BindConveyorType()

Dim strConn=DB_CONN_STRING

Dim mycn As SqlConnection = new SqlConnection(strConn)

Dim manuf As String = manufacturer.selecteditem.value

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.DataTextField="convtp"

convtype.DataValueField="convtp"

convtype.DataSource=ds

convtype.DataBind()

BindChain()

End Sub

Sub BindChain()

Dim strConn=DB_CONN_STRING

Dim mycn As SqlConnection = new SqlConnection(strConn)

Dim Smanufacturer As String = manufacturer.selecteditem.value

Dim Sconvtype As String = convtype.selecteditem.value

Dim SQL As String = "SELECT manufacturer, convtp, chain FROM
Sn_Rollers WHERE (manufacturer = '"+Smanufacturer+"' 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.DataSource=ds

'chain.DataBind()

Dim i As integer

For i = 0 To ds.Tables("Table3").Rows.Count - 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("Table3").Rows(i).Item(2).ToString()

Rb.GroupName="MySel"

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

AddHandler Rb.CheckedChanged, AddressOf BindAssembly_Click

' It is not linking the same sub event BindAssembly_Click() 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.Controls.Add(Rb)

tRow.Cells.Add(tCell_1)

tRow.Cells.Add(tCell_2)

Tbchain.Rows.Add(tRow)

tCell_3.Text="<img
src=chain_images/"+Replace(ds.Tables("Table3").Rows(i).Item(2).ToSt ring(),"
","") +".gif>"

tCell_4.Text="&nbsp;"

tRow.Cells.Add(tCell_3)

tRow.Cells.Add(tCell_4)

Tbchain.Rows.Add(tRow)

next

End Sub

function LoopTextBoxes(ByVal 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(RadioButton) Then

if Ctype(c, RadioButton).Checked=True then

LoopTextBoxes=Ctype(c, RadioButton).Text

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(strConn)

Dim Smanufacturer As String = manufacturer.selecteditem.value

Dim Sconvtype As String = convtype.selecteditem.value

Dim Schain As string

Schain = LoopTextBoxes(Me)

Dim SQL As String = "SELECT manufacturer, convtp, chain, assembly
FROM Sn_Rollers WHERE (manufacturer = '"+Smanufacturer+"' 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.DataTextField="assembly"

Dpassembly.DataValueField="assembly"

Dpassembly.DataSource=ds

Dpassembly.DataBind()

End Sub

Sub BindConveyorType_Click(sender As Object, e As EventArgs)

BindConveyorType()

End Sub

Sub BindChain_Click(sender As Object, e As EventArgs)

BindChain()

End Sub

Sub BindAssembly_Click(sender As Object, e As EventArgs)

BindAssembly()

End Sub

</script>

Thanks

Rod
Jul 19 '05 #1
0 4094

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

Similar topics

3
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...
7
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...
6
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
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...
3
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...
0
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...
19
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...
2
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...
5
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. ...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.