would some kind soul write me two aspx pages?

liunx

Guest
page1.aspx - has a single hypertext column data grid that lists employees sorted by last name.
hyperlink.text = firstName & " " & middleName & lastName 'middleName has a trailing space.
hyperlink.href = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/">http://www.webdeveloper.com/forum/archive/index.php/</a><!-- m -->"page2.aspx?empId="&employeeId

page2.aspx - has a single record form with textboxes per field that displays the record chosen on page1.aspx and allows the record to be updated.

I'm new to asp.net but I'm very confident I could handle this if the data source was an SQL database, however, and heres the kicker, here is my data source:

employees.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<employees
xmlns="http://www.mydom.org/employees"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<employee Id="i100">
<first>Darin</first>
<middle></middle>
<last>Marsh</last>
<phones>
<homePhoneId>p3</homePhoneId>
<workPhoneId extension="531">p1</workPhoneId>
</phones>
<birthDate>
<day>13</day>
<month>8</month>
<year>1965</year>
</birthDate>
</employee>

</employees>

everything that I鎶砮 been reading seems too convoluted and complex to be realistic. Isn't there some plain and simple way to accomplish this? I'll take any TIDs or howTo docs anyone can throw my way. Ultimately, I want to add records and delete them as well. Thanks in advance.

iloveclassicaspThis is pretty plain and simple and not too complex. I'd be willing to write them for you for a trade of cash or services! Otherwise, here are some tips on how to approach it.

First, create an object to handle an employee record. Properties for each employee attribute and methods to handle fetching, inserting, and deleting records, etc.

Then, look into the XmlTextReader and XmlTextWriter to handle the reading and writing of your xml file, which you'll use in your fetch, insert, update, and delete methods.

The idea is that you'll use the XmlTextReader to stuff employee objects for each employee and put them into a collection. Then display that collection on Page1.aspx with a datagrid or literal control or whatever.

On Page2.aspx, you'll get the employeeId from the querystring and then use a method in your employee object to stuff an employee object with the record that matches the EmployeeId. Then you'll use that new object to fill your form elements. Once the user clicks submit, you'll update the employee record based on the employeeId. Use a similar approach for insert and deletes too.

Also, you'll need to grant the read/write permission on the XML file to the user that your application is running as. Ie. "ASPNET"

Let me know if you have any questions or some example code. I think I have some code for reading/writing to XML files.Thanks CStick,

As a test I'm trying to extract the value stored in the Id attribute for a given employeeId here is my function which will set all the employee properties for the class if I can harvest the stinkin id attribute. I know it seems stupid to harvest the id attribute with it being the argument to the function but like I said this is just a test to see if I'm able to harvest anything from the xml file. All I'm getting when I read the classname.emplyeeId is empty string. If I create a line outside the While loop that states "Me.employeeId = 112233" and then read the employeeId property it works fine. Please help






...class properties declared here

Public function fetchEmployee(empId As String) As Integer
Dim recordsAffected As Integer = -1
Dim objReader As New XmlTextReader(employeeXmlFile)

While objReader.Read()
If objReader.NodeType = XmlNodeType.Element Then
If objReader.Value = "employee" Then
objReader.MoveToNextAttribute()
If objReader.Value = empId Then
Me.employeeId = objReader.Text
recordsAffected = 1
End If
End If
End If
End While

return recordsAffected

end function


xml file
<?xml version="1.0" encoding="iso-8859-1"?>
<employees xmlns="http://www.mydom.org/employees" xmlns:lcsGlobals="http://www.mydom.org/globals" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mydom.org/employees employees.xsd">

<employee Id="i100">
<first>Darin</first>
<middle></middle>
<last>Marsh</last>
<lcsGlobals:addresses>
<lcsGlobals:homeAddId>a2</lcsGlobals:homeAddId>
<lcsGlobals:workAddId>a1</lcsGlobals:workAddId>
</lcsGlobals:addresses>
<lcsGlobals:phones>
<lcsGlobals:homePhoneId>p3</lcsGlobals:homePhoneId>
<lcsGlobals:workPhoneId extension="531">p1</lcsGlobals:workPhoneId>
</lcsGlobals:phones>
<emailAddress>[email protected]</emailAddress>
<lcsGlobals:birthDate>
<lcsGlobals:day>13</lcsGlobals:day>
<lcsGlobals:month>8</lcsGlobals:month>
<lcsGlobals:year>1965</lcsGlobals:year>
</lcsGlobals:birthDate>
<lcsGlobals:webAccess>
<lcsGlobals:userName>dMarsh</lcsGlobals:userName>
<lcsGlobals:password>anthem</lcsGlobals:password>
<lcsGlobals:applications>
<lcsGlobals:applicationId>app1</lcsGlobals:applicationId>
</lcsGlobals:applications>
</lcsGlobals:webAccess>
</employee>

</employees>Here's some code that should get you moving a little more. Ask if you need more help.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strAr As System.Collections.Specialized.NameValueCollection = fetchEmployee("i100")

For i As Integer = 0 To strAr.Count - 1
Response.Write(strAr.GetKey(i) & " | " & strAr.Item(i).ToString & "<br />" & vbCrLf)
Next
End Sub


Public Function fetchEmployee(ByVal empId As String) As System.Collections.Specialized.NameValueCollection
Dim strAr As New System.Collections.Specialized.NameValueCollection
Dim str As System.IO.Stream = System.IO.File.Open(Server.MapPath("employees.xml"), IO.FileMode.Open)
Dim objReader As New XmlTextReader(str)

objReader.WhitespaceHandling = WhitespaceHandling.None
objReader.MoveToContent()
objReader.Read()
While Not objReader.GetAttribute("Id") = empId
objReader.Read()
End While

objReader.Read()

While Not objReader.Name = "employee"
Dim name As String = objReader.Name
Dim value As String = objReader.ReadInnerXml
strAr.Add(name, value)
End While

fetchEmployee = strAr

objReader.Close()
str.Close()
End Function
 
Back
Top