473,769 Members | 2,143 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 2439

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

Similar topics

9
1741
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 link buttons to appear next to the row that allows the user to delete the row or edit it.
2
3275
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
1882
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 way to do it, because there is no Visible property available...).
3
4271
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 at:
0
1052
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 which column I click? The first or the last one? I need to make a different in my code when the...
5
2377
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 problems which have not been addressed by various SP's, including the recent SP1 to Framework.NET 1.1,...
0
1242
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
1809
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( "Content-disposition",
3
2630
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. When a new row is created in the datagrid it may or may not be created in the datasource as
9
2728
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 (Page.IsPostBack) Then FillDataGrid()
0
9579
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
9422
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
10208
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9857
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
6662
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();...
0
5294
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...
1
3952
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
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
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.