473,624 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add more than one value onclick

LU
I have a datagrid for viewing and deleting. Under that I
have a drop down with binded info and a button to add the
select drop down item into database.
1User can view datagrid and delete info.
2User can select from drop down, click add button and add
selection to database.
A)Datagrid binds and deletes fine.
B)If I select the first value of drop down addition to
database works fine.
C)<problem>if I select the 2nd value of drop down it adds
2 records into the database when it should only add 1. It
adds 1 record for 1st value of drop down and 1 record for
next value selected.
Code below for review.
*************
<%@ Import Namespace="Syst em.Data"%>
<%@ Import Namespace="Syst em.Data.SqlClie nt" %>
<%@ Page CodeBehind="Vie wItemsSub.aspx. vb" Language="vb"
AutoEventWireup ="false" Inherits="TF.Vi ewItemsSub" %>
<HTML>
<script language="vb" runat="server">

Dim intItem As Integer
Dim strSelect As String
Dim Conn As SqlConnection
Dim Cmd As SqlCommand
Dim DBCommand as SQLDataAdapter
Dim DSPageData as New DataSet
Dim ParmInfo as SQLParameter
Dim NID as Integer '
Dim TheID as String

Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles MyBase.Load

intItem = Int32.Parse(Req uest.QueryStrin g("id"))
Call GetAssignedStaf f()
If Not IsPostBack Then
Call BuildDropDown()
end If
End Sub

Sub GetAssignedStaf f

'Get assigned staff info
Conn = New SqlConnection(" Server=localhos t;Initial
Catalog=CA;Trus ted_Connection= yes;")
strSelect = "Select A.PNID, B.URPNAID, A.IDNum,
A.FirstName, A.LastName, A.MiddleName"
strSelect = strSelect + " from TF_Preassigned_ Table A,
TF_Unit_Request _Preassigned_As signments B"
strSelect = strSelect + " Where (A.PNID In (Select PNID
from TF_Unit_Request _Preassigned_As signments Where "
strSelect = strSelect + " URID = " &intItem & "))"
response.write ("<P>")
response.write (strSelect)
Cmd = New SqlCommand(strS elect, Conn)

Try
Conn.Open()

Datagrid1.DataS ource = cmd.ExecuteRead er()
Datagrid1.DataB ind()
Catch TfHrException As SqlException
TfHrExceptionLa bel.Text = TfHrException.M essage
Finally
Conn.Close()
End Try
'end assigned staff info
End Sub
'preassigned staff options

Sub Click_Grid(ByVa l Sender As Object, ByVal E as
DataGridCommand EventArgs)
response.write ("hello")

TheID = E.Item.Cells(0) .Text
strSelect ="Delete from
TF_Unit_Request _Preassigned_As signments Where URPNAID
= "&TheID
Conn = New SqlConnection(" Server=localhos t;Initial
Catalog=CA;Trus ted_Connection= yes;")

Cmd.CommandText = (strSelect)
response.write ("<P>")
response.write( strSelect)
Cmd.Connection = Conn
Cmd.Connection. Open
Cmd.ExecuteNonQ uery()
Conn.Close
Call GetAssignedStaf f()
End Sub

Sub Edit_Grid(sende r As Object, e As
DataGridCommand EventArgs)
DataGrid1.EditI temIndex = e.Item.ItemInde x
Call GetAssignedStaf f()
End Sub

Sub Update_Grid(ByV al Sender as Object, ByVal E as
DataGridCommand EventArgs)

End Sub
'end assigned staff options.

Sub BuildDropDown()

Conn = New SqlConnection(" Server=localhos t;Initial
Catalog=CA;Trus ted_Connection= yes;")

'strSelect = "Select * from TF_Preassigned_ Table"
DBCommand = New SQLDataAdapter( "Select PNID, LastName,
FirstName,IDNum from TF_Preassigned_ Table Order by
LastName", Conn)
'response.write (strSelect)
DBCommand.Fill( DSPageData, "s_Table")
Dim DynColumn As New DataColumn()
With DynColumn
..ColumnName = "FullName"
..DataType = System.Type.Get Type("System.St ring")
..Expression = "LastName+ ' ' +FirstName+ ' ' + IDNum"
End With
DSPageData.Tabl es("s_Table").C olumns.Add(DynC olumn)
Assigned.DataTe xtField = "FullName"
Assigned.DataVa lueField = "PNID"
Assigned.DataSo urce = DSPageData.Tabl es
("s_Table").Def aultView
Assigned.DataBi nd()
Assigned.Items. Insert(0, "Select one")
Conn.Close()
End Sub

Sub Add_Click(send as object, e as system.eventarg s)

'intItem = Int32.Parse(Req uest.QueryStrin g("id"))
'response.write (intItem)
'response.write ("<BR>")

response.write (Assigned.Selec tedItem.Value)
if Assigned.Select edIndex = 0 then
response.write( "Must select a nurse")
else
Conn = New SqlConnection(" Server=localhos t;Initial
Catalog=CA;Trus ted_Connection= yes;")
Cmd = New SQLCommand
("TF_sp_insert_ preassigned_ass ignment", Conn)
Cmd.CommandType = CommandType.Sto redProcedure
'Add Return Value Parameter
ParmInfo = Cmd.Parameters. Add("ReturnValu e", SqlDbType.Int)
ParmInfo.Direct ion = ParameterDirect ion.ReturnValue
'Add UID input parameter
Cmd.Parameters. Add("@URID", intItem)
Cmd.Parameters. Add("@PNID", Assigned.Select edItem.Value)
Cmd.Parameters. Add("@CreatedDT M", datetime.now)
Cmd.Parameters. Add("@CreatedBy ", "Admin")
Cmd.Parameters. Add("@ModifiedD TM", DateTime.Now)
Cmd.Parameters. Add("@ModifiedB y", "Admin")
Conn.Open()
Cmd.ExecuteNonQ uery()
NID = Cmd.Parameters( "ReturnValue"). Value
Conn.Close()
response.write( "<P>")
response.write( " added")
Call GetAssignedStaf f()
'Call BuildDropDown()
end if
End Sub

</script>
<body>
<form runat="server">
<asp:Label ID="TfHrExcepti onLabel"
runat="server" />
<asp:Label ID="Label1"
runat="server" />
<BR>
<asp:DataGrid ID="Datagrid1"
AutoGenerateCol umns="false" enableviewstate ="false"
runat="server"
ItemStyle-
BackColor="#DED FDE" AlternatingItem Style-
BackColor="Ligh tSteelBlue" HeaderStyle-Font-Bold="True"
HeaderStyle-
ForeColor="Whit e" HeaderStyle-BackColor="Blac k" Font-
Names="Verdana" Font-Size="X-Small"
ForeColor="Blac k"
BackColor="Whit e" Cellpadding="3" GridLines="None "
CellSpacing="1" oneditcommand=" Edit_Grid"

onupdatecommand ="Update_Gri d"
onitemcommand=" Click_Grid">
<Columns>
<asp:BoundColum n
HeaderText="Ass ignmentID" DataField="URPN AID" />
<asp:BoundColum n
Headertext="ID" DataField="IDNu m" />
<asp:BoundColum n
HeaderText="Fir st name" DataField="Firs tName" />
<asp:BoundColum n
HeaderText="Las t name" DataField="Last Name" />
<asp:ButtonColu mn
HeaderText="Cli ck to delete" ButtonType="Pus hButton"
Text="Delete record" />

</Columns>
</asp:DataGrid>

<asp:DropDownLi st
id="Assigned"
runat="server"/>
<asp:Button id="Add"
Text="Add "
OnClick="Add_Cl ick"
Runat="server"> </asp:Button>
</form>
<P></P>
</body>
</HTML>

Jul 21 '05 #1
0 3696

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

Similar topics

1
5523
by: koen colen | last post by:
Hello group, I hope you guys can help me out, I am modifying a piece of code from Joe Norman, I did found the code here: http://www.intranet2internet.com/public/default.asp?PAGE=sscript&ID=3 My question: How can I save the value's of a form to a cookie, but in the textarea's of that form the "hard returns" must be saved with it?
3
11931
by: Eric Chang | last post by:
I was working on this simple form with radio boxes. And when I click on one of the radio box, it tell me the value is "undefined" Why is that ? I did defined the value of each radio box: <input type=radio name='Usetax' value='basic' onClick='document.myform.amount.value=document.myform.Usetax.value'> <input type=radio name='Usetax' value='no' onClick='document.myform.amount.value=document.myform.Usetax.value'> <input type=radio...
8
67456
by: KS | last post by:
Just to show some code to show the consept. <img id="date" onclick="javascript:show_calendar();" src="/PlexSysWeb/images/show-calendar.gif" width=20 height=18 border=0> What i want the javascript to do is change the onclick value of the <IMG> tag above, by calling the test function from the same webpage by onclick on a button.
1
3397
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with ***********************, I've included all the code incase that isn't where the problem is. Any help would be hugely appreciated. Mick
2
2151
by: joltman | last post by:
OK, this is kind of hard to explain, so I'll do my best: I have a form where I have a row where there could be multiple entries, so I have a link where it will dynamically add another row like it, and this can happen as many times as you click on the link. This row consists of 2 drop-down boxes. Depending on the selection of the first drop-down box, the second drop-down box is either disabled or enabled. The problem is on these dynamically...
3
5448
by: Robin Day | last post by:
I run some code on the changed event of checkbox lists. Its quite simple, nothing more than showing / hiding some other parts of the page. Using Autopostback and Server side code works fine, but is far too slow, especially if the users are on modems. I need to quite simply, add some java code to the onclick event of the input tags of a checkboxlist. However... Attributes.Add adds the onclick attribute and code to the outlying table that...
5
1993
by: Novice Computer User | last post by:
Hi. Can somebody PLEASE help. Here is a .php script. Right now, the minimum amount of time (i.e. duration) allowed is 1 month. However, I want to be able to reduce the minimum amount of time to 2 days (i.e. 48 hours). Can somebody PLEASE PLEASE tell me what I need to change in this file to do this? Here is a copy - thanks enormously in advance: <html> <head>
5
2863
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the elements in the form, including those that are added dynamically. I use document.getElementsByName('Field Name')to achieve the same.
1
1571
by: nowitsoverx | last post by:
I'm just trying to test something out to see if I can get it working but I'm a little stuck. I have two frames. The left one has a menu of radio buttons. I want it so when you click on the radio button it will show the picture in the right frame. When you click on a different radio button I want it to show that picture to the right of the other picture that's already there. When you click another radio button I want it to show that picture...
2
1923
by: sbettadpur | last post by:
Hi everybody, Hi iam strugling with more than one submit buttons with in one form here is my code <form method="post" action="Offer.php" name='issueFrm' onSubmit="return fullOfferfields();"> OFFER <input type=image src="amarok_rewind.png " title="rewind" > <input type=image src="amarok_back.png" title="back"> <input type="text" size=3 name='txt'>&nbsp;<input type=image src="amarok_next.png " title="next" >&nbsp;<input type=image...
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
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,...
0
8620
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...
0
8474
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
7158
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...
0
5563
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();...
1
2605
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
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.