Click here to Skip to main content
15,913,773 members
Home / Discussions / XML / XSL
   

XML / XSL

 
QuestionArticle help?!? Pin
yourxlife25-Aug-04 2:07
yourxlife25-Aug-04 2:07 
GeneralVerification of Login Page using XML Pin
DotNet24-Aug-04 20:19
DotNet24-Aug-04 20:19 
General.NET newbie has question RE: XmlTextWriter Pin
Member 127129724-Aug-04 1:22
Member 127129724-Aug-04 1:22 
GeneralRe: .NET newbie has question RE: XmlTextWriter Pin
Member 127129726-Aug-04 22:34
Member 127129726-Aug-04 22:34 
GeneralRe: .NET newbie has question RE: XmlTextWriter Pin
DavidNohejl7-Oct-04 10:59
DavidNohejl7-Oct-04 10:59 
GeneralRe: .NET newbie has question RE: XmlTextWriter Pin
Anonymous7-Oct-04 22:51
Anonymous7-Oct-04 22:51 
GeneralRe: .NET newbie has question RE: XmlTextWriter Pin
Anonymous7-Oct-04 22:51
Anonymous7-Oct-04 22:51 
GeneralDatagrid cannot displayed. Pin
DotNet23-Aug-04 3:24
DotNet23-Aug-04 3:24 
Hie,
All I want to display what is on the XML put on the datagrid at the same time, want a delete hyperlink to delete my user.
How to do it?

The Edit or Add function can ignore it or the best is delete it.
Let's look at the coding.

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Inherits="System.Web.UI.Page" %>


<title>Delete User Account

dim gXmlfile as string = "~/data/Users.xml"
dim gXmlPath as string

' =================================

Sub Page_Load(Src As Object, E As EventArgs)

gxmlpath = server.mappath( gXmlfile ) 'file is in same folder as page

If Not (IsPostBack)
DataLoad("UserEmail")
End If
End Sub

' ========================================

Sub DataLoad(parmsort as string)
Dim ds As New DataSet
Dim FS As New FileStream(Server.MapPath(gXmlFile), FileMode.Open)
ds.ReadXml(FS)

' 02/14/02 pchu handle an empty file ---------------------------
if ds.tables.count = 0 then
ds.tables.add( MakeBooksTable() )
end if
trace.warn ( "rowcount1 = " , cstr(ds.Tables(0).rows.count ))

' 02/14/02 pchu ---------------------------
' Add code to sort the dataview if parmsort is present

'ok let's get fancy and insert a blank row at the top
dim sw1 as integer = 1
select case sw1
case 1
dim dr as datarow = ds.Tables(0).newrow()
'put something in the first column ISBN
dr("UserEmail") = " Add UserEmail"
ds.Tables(0).rows.insertat(dr, 0)
trace.warn ( "rowcount2 = " , cstr(ds.Tables(0).rows.count ))
end select

'create dv and bind it to datagrid
dim dv as dataview
dv = new DataView(ds.Tables(0))
if parmsort.length > 0 then
dv.sort = parmsort
end if



MyDataGrid.DataSource = dv
'old MyDataGrid.DataSource = new DataView(ds.Tables(0))
' 02/14/02 pchu ---------------------------

MyDataGrid.DataBind()
FS.close()
END SUB

' ========================================
Sub DataSort(Src As Object, E As DataGridSortCommandEventArgs)
' Bug if we sort, then Edit Item Becomes Wrong
IF MyDataGrid.EditItemIndex=-1 THEN
DataLoad(e.sortexpression)
ELSE
response.write ("Can't sort until editing is done!")
END IF
End Sub

Sub DataDelete(Sender As Object, E As DataGridCommandEventArgs)
dim deletekey as string
If MyDataGrid.EditItemIndex=-1 Then
deletekey=MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
response.write ("Delete completed for key = " & deletekey)
Else
response.write ("Can't delete until editing is done!")
End If

'' Dim currentRow As Integer = e.Item.DataSetIndex
Dim currentRow As Integer = e.Item.itemindex

'02/16/02 BugFix: because the datagrid has an insert row which is NOT in the
' in the dataset table, we have to subtract one to compensate for the that fact
currentrow = currentrow - 1 'bug fix: subtract 1 because the grid has a insert row

trace.warn (" current row to delete ", cstr(currentrow) )
' reload the XML file into a dataset
Dim ds As New DataSet()
ds.ReadXml(Server.MapPath(gXmlFile))

' get a reference to this row of data
Dim row As DataRow = ds.Tables(0).Rows( currentrow )

row.delete() '-- kill this row in the dataset (disabled for example)

' save the updated dataset to the XML file
ds.WriteXml(Server.MapPath(gXmlFile))

mydatagrid.EditItemIndex = -1 'exit delete mode

dataload("") ' redisplay and rebind datagrid

END SUB

Sub DataEdit(Sender As Object, E As DataGridCommandEventArgs)
DIM editkey as string
trace.warn ("e.item.itemindex = ", cstr(e.item.itemindex) )
MyDataGrid.EditItemIndex = Cint(E.Item.ItemIndex )
editkey=MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
trace.warn ("page.aspx", "To Be Edited" & editkey)
SetEditMode( "on" )
DataLoad("")
End Sub

' ===================================
public sub dg_itemcreated ( sender as object, e as datagriditemeventargs )

if e.item.itemindex = 0 then 'first row
dim lbDelete as linkbutton = e.item.cells(0).controls(0)

trace.warn ("page.aspx", "lbDelete = " & lbDelete.text )
if lbDelete.text = "Delete User" then
lbDelete.text = ""
end if
end if

if e.item.itemindex > 0 then 'first row
select case e.item.itemtype
case listitemtype.item
dim mydeletebutton as tablecell
mydeletebutton = e.item.cells(0)
mydeletebutton.attributes.add("onclick", _
"return confirm('Are you sure you want to Delete?');" )
case listitemtype.alternatingitem
dim mydeletebutton as tablecell
mydeletebutton = e.item.cells(0)
mydeletebutton.attributes.add("onclick", _
"return confirm('Are you sure you want to Delete?');" )

end select
end if
end sub

' =========================

Private Function MakeUserTable() As DataTable

' Create a new DataTable titled 'Login.'
Dim theTable As DataTable = new DataTable("Login")
' Add two column objects to the table.
Dim theColumn1 As DataColumn = new DataColumn()
theColumn1.DataType = System.Type.GetType("System.String")
theColumn1.ColumnName = "UserEmail"
theTable.Columns.Add(theColumn1)

Dim theColumn2 As DataColumn = new DataColumn()
theColumn2.DataType = System.Type.GetType("System.String")
theColumn2.ColumnName = "UserPassword"
theTable.Columns.Add(theColumn2)

' Create an array for DataColumn objects.
Dim keys(0) As DataColumn
keys(0) = theColumn1
theTable.PrimaryKey = keys
' Return the new DataTable.
MakeUserTable = theTable
End Function




Delete User Account




<asp:datagrid id="MyDataGrid" style="Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP: 56px"
="" runat="server" onitemcreated="dg_itemcreated" font-names="Verdana" headerstyle-font-size="10pt" headerstyle-backcolor="lightblue" font-size="8pt" font-name="Verdana" cellpadding="3" bordercolor="Black" backcolor="White" datakeyfield="isbn" ondeletecommand="DataDelete" allowsorting="True" width="400px" height="56px">
<headerstyle font-size="10pt" backcolor="LightBlue">
<columns>
<asp:buttoncolumn text="Delete User" commandname="mydeletebutton">






-------------------------------------------------------------------------

Users.xml file


<login>
<users>
<useremail>smurf@hotmail.com
<userpassword>CC0C3DBD8A231B92307C537673CFB26BDB24B421

<users>
<useremail>Duncan@yahoo.com
<userpassword>A9C53C9934EF3B01D0873BF3C6A9B291749A6454

<users>
<useremail>james@home.com
<userpassword>EB01D8F828A6C9A20BE4534E72E049AAF41503DF




Worried,
GeneralXML navigation help needed Pin
liyang yu22-Aug-04 9:06
liyang yu22-Aug-04 9:06 
GeneralRe: XML navigation help needed Pin
Pradeep Shamarao6-Sep-04 21:53
Pradeep Shamarao6-Sep-04 21:53 
GeneralXml Parsing &amp; Validating Pin
SR7717-Aug-04 10:52
SR7717-Aug-04 10:52 
GeneralRe: Xml Parsing &amp; Validating Pin
David Salter23-Aug-04 4:07
David Salter23-Aug-04 4:07 
GeneralNo correct xhtml from XML and XSL Pin
Gumbah13-Aug-04 0:06
Gumbah13-Aug-04 0:06 
GeneralRe: No correct xhtml from XML and XSL Pin
ChrisAdams15-Aug-04 19:37
ChrisAdams15-Aug-04 19:37 
GeneralRe: No correct xhtml from XML and XSL Pin
Gumbah15-Aug-04 21:01
Gumbah15-Aug-04 21:01 
QuestionPulling Values From An XML File - Recommendations? Pin
Member 66660712-Aug-04 6:11
Member 66660712-Aug-04 6:11 
GeneralEvaluating XPath expressions on Windows CE Pin
Kot_Begemot6-Aug-04 5:52
Kot_Begemot6-Aug-04 5:52 
GeneralRegular Expression of XML document Pin
Rashid_Mehmood5-Aug-04 14:53
Rashid_Mehmood5-Aug-04 14:53 
GeneralRe: Regular Expression of XML document Pin
abu-alSaber16-Aug-04 22:12
abu-alSaber16-Aug-04 22:12 
GeneralMerging of two XML documents Pin
dabs5-Aug-04 7:15
dabs5-Aug-04 7:15 
GeneralRe: Merging of two XML documents Pin
ChrisAdams11-Aug-04 23:49
ChrisAdams11-Aug-04 23:49 
GeneralRe: Merging of two XML documents Pin
dabs12-Aug-04 0:31
dabs12-Aug-04 0:31 
GeneralRe: Merging of two XML documents Pin
Praveen Nayak6-Sep-04 0:11
Praveen Nayak6-Sep-04 0:11 
Generalmicrosoft vb script runtime error'800a01a8' is harassing me Pin
chmonalisa4-Aug-04 23:35
chmonalisa4-Aug-04 23:35 
Generalmicrosoft vb script runtime error'800a01a8' is harassing me Pin
chmonalisa4-Aug-04 23:33
chmonalisa4-Aug-04 23:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.