473,404 Members | 2,213 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,404 software developers and data experts.

datagrid and problems

lu
I have a page with datagrid (for viewing,
delete,edit,update) and text fields with button to add
info to database.
When user comes to page the datagrid selects info from
database, binds in columns, and adds a delete buttoncolumn
and editcommandcolumn. Below that, I have several text
boxes with a button with an onclick event to add new
information to the database table the grid pulls from.

A)Select Info binds fine.
B)Sumbitting values to be added works fine.
C)Delete option works fine.
D)<problem>Edit option tries to runs the delete sub , then
the edit sub.
E)<problem>Update option triggers the
RequiredFieldValidator used when new values are being
added.
F)Code is below for review
**********

<%@ Import NameSpace="System.Data.SqlClient" %>
<%@ Import NameSpace="System.Data"%>
<%@ Page Language="vb" %>
<HTML>
<script runat="Server">
Dim Conn As SqlConnection
Dim strSelect As String 'string based query
Dim Cmd As SqlCommand 'will hold sql commands
Dim ParmInfo as SQLParameter
Dim NID as Integer 'holds nurse computer generated id
Dim DBCommand as SQLDataAdapter

Sub Page_Load
Call BuildGrid()
End Sub

Sub BuildGrid
Conn = New SqlConnection("Server=localhost;Initial
Catalog=CCAN;Trusted_Connection=yes;")
strSelect = "Select PNID, LastName, FirstName, MiddleName,
IDNum, SSNum, Email, Phone1, Phone2 from
TF_Preassigned_Table Order by LastName "

'response.write (strSelect)
Cmd = New SqlCommand(strSelect, Conn)
Try
Conn.Open()
dtrItem.DataSource = cmd.ExecuteReader()
dtrItem.DataBind()
Catch TfHrException As SqlException
TfHrExceptionLabel.Text = TfHrException.Message
Finally
Conn.Close()
End Try
End Sub

Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Conn = New SqlConnection("Server=localhost;Initial
Catalog=CCAN;Trusted_Connection=yes;")
Cmd = New SQLCommand("TF_sp_insert_preassigned_info", Conn)
Cmd.CommandType = CommandType.StoredProcedure
'Add Return Value Parameter
ParmInfo = Cmd.Parameters.Add("ReturnValue", SqlDbType.Int)
ParmInfo.Direction = ParameterDirection.ReturnValue
'Add UID input parameter
Cmd.Parameters.Add("@ID", IDNum.Text)
Cmd.Parameters.Add("@FirstName", FirstName.Text)
Cmd.Parameters.Add("@LastName", LastName.Text)
Cmd.Parameters.Add("@MiddleName", MiddleName.Text)
Cmd.Parameters.Add("@SSNum", SSNum1.Text)
Cmd.Parameters.Add("@UserEmail", Email.Text)
Cmd.Parameters.Add("@Phone1", Phone1.Text)
Cmd.Parameters.Add("@Phone2", Phone2.Text)
Conn.Open()
Cmd.ExecuteNonQuery()
NID = Cmd.Parameters("ReturnValue").Value
Conn.Close()
Call BuildGrid()
End Sub

Sub Click_Grid(ByVal Sender As Object, ByVal E as
DataGridCommandEventArgs)

Dim TheID as String
TheID = E.Item.Cells(0).Text
response.write (TheID)
Conn = New SqlConnection("Server=localhost;Initial
Catalog=CCAN;Trusted_Connection=yes;")
Cmd = New SQLCommand("TF_sp_delete_preassigned_info", Conn)
Cmd.CommandType = CommandType.StoredProcedure

'Add Return Value Parameter
ParmInfo = Cmd.Parameters.Add("@Progress", SqlDbType.Int)
ParmInfo.Direction = ParameterDirection.Output
'Add UID input parameter

Cmd.Parameters.Add("@PNID", TheID)
'Cmd.CommandText = "Delete from TF_Preassigned_table Where
PNID = "&TheID
Cmd.Connection = Conn
Cmd.Connection.Open
Cmd.ExecuteNonQuery()
NID = Cmd.Parameters("@Progress").Value
Conn.Close
if NID = 0 Then
response.write ("The could not be deleted.")
else
response.write ("Record found")
end if
Call BuildGrid()
End Sub

Sub Edit_Grid(sender As Object, e As
DataGridCommandEventArgs)
dtrItem.EditItemIndex = e.Item.ItemIndex
Call BuildGrid()
End Sub

Sub Update_Grid(ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
Dim TheID as String
Dim LastName as String
Dim FirstName as String
Dim ID as String
Dim SSNUM as Integer
Dim Email as String

TheID = E.Item.Cells(0).Text
LastName= CType(e.Item.Cells(1).Controls(0), TextBox).Text
FirstName= CType(e.Item.Cells(2).Controls(0), TextBox).Text
ID = CType(e.Item.Cells(3).Controls(0), TextBox).Text
SSNUM= CType(e.Item.Cells(4).Controls(0), TextBox).Text
Email= CType(e.Item.Cells(5).Controls(0), TextBox).Text
'havent finished this
End Sub
</script>
<body>
<form runat="server" ID="Form1">
<asp:Label ID="TfHrExceptionLabel" runat="server" />
<BR>
<asp:DataGrid ID="dtrItem"
AutoGenerateColumns="false" enableviewstate="false"
runat="server" ItemStyle-BackColor="#DEDFDE"
AlternatingItemStyle-BackColor="LightSteelBlue"
HeaderStyle-Font-Bold="True" HeaderStyle-ForeColor="White"
HeaderStyle-BackColor="Black" Font-Names="Verdana" Font-
Size="X-Small" ForeColor="Black" BackColor="White"
Cellpadding="3" GridLines="None" CellSpacing="1"

oneditcommand="Edit_Grid"
onupdatecommand="Update_Grid"
onitemcommand="Click_Grid"

<Columns>
<asp:BoundColumn HeaderText="System ID" DataField="PNID"
readonly="true"/>
<asp:BoundColumn HeaderText="Last name" DataField
="LastName"/>
<asp:BoundColumn HeaderText="First name"
DataField="FirstName"/>
<asp:BoundColumn Headertext="ID" DataField="IDNum"/>
<asp:BoundColumn HeaderText="Social Security"
DataField="SSNum"/>
<asp:BoundColumn HeaderText="Email" DataField="Email"/>
<asp:ButtonColumn HeaderText="Click to delete"
ButtonType="PushButton" Text="Delete record" />
<asp:EditCommandColumn EditText="Edit" UpdateText="Update"
ItemStyle-Wrap="False" HeaderText="Edit" HeaderStyle-
Wrap="False"/>
</Columns>

</asp:DataGrid>
<br>
<table border="1">
<tr>
<td
colspan="2"><asp:Label ID="TableHeading" text="Add new
nurse" Runat="server"></asp:Label></td>
</tr>
<tr>
<td>
<asp:label
id="Label1" Runat="server" text="ID:"></asp:label>
</td>
<td>

<asp:textbox id="IDNum" runat="server"
columns="10"></asp:textbox>

<asp:RequiredFieldValidator ID="id"
ControlToValidate="IDNum" Display="Dynamic"
Runat="server">You must enter an
ID.</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:label
id="Label2" Runat="server" text="First name:"></asp:label>
</td>
<td>

<asp:textbox id="FirstName" runat="server"
columns="10"></asp:textbox>

<asp:RequiredFieldValidator ID="fname"
ControlToValidate="FirstName" Display="Dynamic"
Runat="server">You must enter first
name.</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:label
id="Label3" Runat="server" text="Last name:"></asp:label>
</td>
<td>

<asp:textbox id="LastName" runat="server"
columns="10"></asp:textbox>

<asp:RequiredFieldValidator ID="lname"
ControlToValidate="LastName" Display="Dynamic"
Runat="server">You must enter last
name.</asp:RequiredFieldValidator>
</td>
<tr>
<td>
<asp:label
id="Label4" Runat="server" text="Middle name:"></asp:label>
</td>
<td>

<asp:textbox id="MiddleName" runat="server"
columns="10"></asp:textbox>
</td>
</tr>
<tr>
<td>
<asp:label
id="Label5" Runat="server" text="Social
security:"></asp:label>
</td>
<td>

<asp:textbox id="SSNum1" runat="server"
columns="9" MaxLength="9"></asp:textbox>

<asp:RequiredFieldValidator Runat="server"
ID="ReqSSNum" ControlToValidate="SSNum1"

ErrorMessage="You must provide a social security
number"

display="Dynamic"/>

<asp:RegularExpressionValidator Runat="server"
ID="ReqExpSSNum"

ControlToValidate="NurseSSNum1"
ValidationExpression="^\d{3}\d{2}\d{4}$"

ErrorMessage= "Social security must be in the
format XXXXXXXXX"

display="Dynamic"
/>

</td>
</tr>
<tr>
<td>
<asp:label
id="Label6" Runat="server" text="Email
address:"></asp:label>
</td>
<td>

<asp:textbox id="Email" runat="server"
columns="10"></asp:textbox>
</td>
</tr>
<tr>
<td>
<asp:label
id="Label7" Runat="server" text="Phone 1:"></asp:label>
</td>
<td>

<asp:textbox id="Phone1" runat="server"
columns="10"></asp:textbox>
</td>
</tr>
<tr>
<td>
<asp:label
id="Label8" Runat="server" text="Phone 2:"></asp:label>
</td>
<td>

<asp:textbox id="Phone2" runat="server"
columns="10"></asp:textbox>
</td>
</tr>
</table>
<asp:Button id="Add" Text="Add
Nurse" OnClick="SubmitBtn_Click"
Runat="server"></asp:Button>
<P>
<asp:HyperLink id="hyplnk"
runat="server" Text="Main menu"
navigateurl="../TF"
/>
</form>
</body>
</HTML>

Nov 22 '05 #1
0 764

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

Similar topics

9
by: Lina | last post by:
Hi, Can anyone tell me if it is possible to add link buttons to a datagrid that has its source set to a datatable that i have created? i.e i want the user to be able to select a room from...
2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
3
by: Igor Mendizabal | last post by:
Hello, We're doing our own datagrid based on the System.windows.forms.datagrid control, and are having some problems with horizontal scrolling. In general, we construct our datagrid adding a...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
0
by: THM5101 | last post by:
Hello I have two problems with my dataGrid. I created dataGrid with 4 columns. The first and the last one are LinkButton type, the second and third are Bound Column type. My problems are:...
5
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes,...
0
by: Linus | last post by:
Hi, I have a datagrid nested inside another datagrid, the edit/update/cancel command works fine on the outter datagrid but I'm having problems with the inner one. There are 2 problems and here's...
3
by: nkunkov | last post by:
Hi, I have read a lot of articles in this newsgroup about how to solve this problem but found no solution. I'm trying to export a C# datagrid to Excel file. Here is my code that I have also...
3
by: simchajoy2000 | last post by:
Hi, I have been working with datagrids a lot in the past two weeks and I am running across a lot of problems. Maybe there is no way around these problems but I hope there are and someone out...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.