473,573 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid and problems

lu
I have a page with datagrid (for viewing,
delete,edit,upd ate) 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 editcommandcolu mn. 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>Upda te option triggers the
RequiredFieldVa lidator used when new values are being
added.
F)Code is below for review
**********

<%@ Import NameSpace="Syst em.Data.SqlClie nt" %>
<%@ Import NameSpace="Syst em.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=localhos t;Initial
Catalog=CCAN;Tr usted_Connectio n=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(strS elect, Conn)
Try
Conn.Open()
dtrItem.DataSou rce = cmd.ExecuteRead er()
dtrItem.DataBin d()
Catch TfHrException As SqlException
TfHrExceptionLa bel.Text = TfHrException.M essage
Finally
Conn.Close()
End Try
End Sub

Sub SubmitBtn_Click (Sender As Object, E As EventArgs)
Conn = New SqlConnection(" Server=localhos t;Initial
Catalog=CCAN;Tr usted_Connectio n=yes;")
Cmd = New SQLCommand("TF_ sp_insert_preas signed_info", 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("@ID", IDNum.Text)
Cmd.Parameters. Add("@FirstName ", FirstName.Text)
Cmd.Parameters. Add("@LastName" , LastName.Text)
Cmd.Parameters. Add("@MiddleNam e", 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.ExecuteNonQ uery()
NID = Cmd.Parameters( "ReturnValue"). Value
Conn.Close()
Call BuildGrid()
End Sub

Sub Click_Grid(ByVa l Sender As Object, ByVal E as
DataGridCommand EventArgs)

Dim TheID as String
TheID = E.Item.Cells(0) .Text
response.write (TheID)
Conn = New SqlConnection(" Server=localhos t;Initial
Catalog=CCAN;Tr usted_Connectio n=yes;")
Cmd = New SQLCommand("TF_ sp_delete_preas signed_info", Conn)
Cmd.CommandType = CommandType.Sto redProcedure

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

Cmd.Parameters. Add("@PNID", TheID)
'Cmd.CommandTex t = "Delete from TF_Preassigned_ table Where
PNID = "&TheID
Cmd.Connection = Conn
Cmd.Connection. Open
Cmd.ExecuteNonQ uery()
NID = Cmd.Parameters( "@Progress").Va lue
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(sende r As Object, e As
DataGridCommand EventArgs)
dtrItem.EditIte mIndex = e.Item.ItemInde x
Call BuildGrid()
End Sub

Sub Update_Grid(ByV al Sender as Object, ByVal E as
DataGridCommand EventArgs)
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.Ce lls(1).Controls (0), TextBox).Text
FirstName= CType(e.Item.Ce lls(2).Controls (0), TextBox).Text
ID = CType(e.Item.Ce lls(3).Controls (0), TextBox).Text
SSNUM= CType(e.Item.Ce lls(4).Controls (0), TextBox).Text
Email= CType(e.Item.Ce lls(5).Controls (0), TextBox).Text
'havent finished this
End Sub
</script>
<body>
<form runat="server" ID="Form1">
<asp:Label ID="TfHrExcepti onLabel" runat="server" />
<BR>
<asp:DataGrid ID="dtrItem"
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="Sys tem ID" DataField="PNID "
readonly="true"/>
<asp:BoundColum n HeaderText="Las t name" DataField
="LastName"/>
<asp:BoundColum n HeaderText="Fir st name"
DataField="Firs tName"/>
<asp:BoundColum n Headertext="ID" DataField="IDNu m"/>
<asp:BoundColum n HeaderText="Soc ial Security"
DataField="SSNu m"/>
<asp:BoundColum n HeaderText="Ema il" DataField="Emai l"/>
<asp:ButtonColu mn HeaderText="Cli ck to delete"
ButtonType="Pus hButton" Text="Delete record" />
<asp:EditComman dColumn EditText="Edit" UpdateText="Upd ate"
ItemStyle-Wrap="False" HeaderText="Edi t" HeaderStyle-
Wrap="False"/>
</Columns>

</asp:DataGrid>
<br>
<table border="1">
<tr>
<td
colspan="2"><as p:Label ID="TableHeadin g" 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:RequiredFi eldValidator ID="id"
ControlToValida te="IDNum" Display="Dynami c"
Runat="server"> You must enter an
ID.</asp:RequiredFie ldValidator>
</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:RequiredFi eldValidator ID="fname"
ControlToValida te="FirstName" Display="Dynami c"
Runat="server"> You must enter first
name.</asp:RequiredFie ldValidator>
</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:RequiredFi eldValidator ID="lname"
ControlToValida te="LastName" Display="Dynami c"
Runat="server"> You must enter last
name.</asp:RequiredFie ldValidator>
</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:RequiredFi eldValidator Runat="server"
ID="ReqSSNum" ControlToValida te="SSNum1"

ErrorMessage="Y ou must provide a social security
number"

display="Dynami c"/>

<asp:RegularExp ressionValidato r Runat="server"
ID="ReqExpSSNum "

ControlToValida te="NurseSSNum1 "
ValidationExpre ssion="^\d{3}\d {2}\d{4}$"

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

display="Dynami c"
/>

</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="Submit Btn_Click"
Runat="server"> </asp:Button>
<P>
<asp:HyperLin k id="hyplnk"
runat="server" Text="Main menu"
navigateurl="../TF"
/>
</form>
</body>
</HTML>

Jul 21 '05 #1
0 2424

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

Similar topics

9
1727
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 various comboboxes and textboxes on my form. when they are satisfied they press OK. the row is then displayed in my datagrid. I now automaticcaly want 2...
2
3254
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 use the F2 key to enter edit mode and then hit TAB or ESCAPE without actually editing the value, dotnet crashes with a null reference error.
3
1870
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 tablestyle and gridcolumnstyles to that tablestyle. If we have invisible columns, we add the gridcolumnstyle with Width = 0 (couldn't find any other...
3
4247
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 several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is...
0
1046
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: 1. When I click on one of the LinkButton column(first or last column), I activate the ItemCommand event of the dataGrid. My problem is how can I know on...
5
2364
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, check boxes, date pickers, combo boxes and datagrids). I have been coding alone on this project for about a year, and I have experienced many...
0
1235
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 the code for my inner datagrid's EditCommand: public void dgInner_EditCommand(object sender, DataGridCommandEventArgs e) {
3
1801
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 found on google: MyDataGrid.EnableViewState = false; MyPage.Response.Clear(); MyPage.Response.Buffer = true; MyPage.Response.AddHeader(...
3
2615
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 there can advise me on how to do it. 1. The biggest problem I am finding is that the datagrid does not update the datagrid.datasource very well. ...
9
2711
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not...
0
7783
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...
0
7701
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...
0
8029
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7794
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...
0
6424
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...
1
5600
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...
0
5293
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...
0
3734
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...
1
1307
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.