How do I read from a datasource and write to xml (rss)? using asp.net either gridview or form. I'm using this code behind.
Imports
System.Web
Imports
System.Web.UI
Imports
System.Web.UI.WebControls
Imports
System.Net
Imports
System.Xml
Imports
System.IO
Imports
System.Linq
Imports
System.Data
Imports
System.Xml.XmlWriter
Partial
Public Class XML
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
BindGridView()
End If
End Sub
Protected Sub BindGridView()
Dim dsGridViewXMLEditDeleteUpdate As New DataSet()
dsGridViewXMLEditDeleteUpdate.ReadXml(Server.MapPath(
"./App_Data/XMLFile.xml"))
gridviewXMLInsertEditDelete.DataSource = dsGridViewXMLEditDeleteUpdate
gridviewXMLInsertEditDelete.DataBind()
gridviewXMLInsertEditDelete.ShowFooter =
True
End Sub
Protected Sub gridviewXMLInsertEditDelete_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
BindGridView()
Dim dsGridViewXMLDelete As DataSet = DirectCast(gridviewXMLInsertEditDelete.DataSource, DataSet)
dsGridViewXMLDelete.Tables(0).Rows(gridviewXMLInsertEditDelete.Rows(e.RowIndex).DataItemIndex).Delete()
dsGridViewXMLDelete.WriteXml(Server.MapPath(
"./App_Data/XMLFile.xml"))
BindGridView()
End Sub
Protected Sub gridviewXMLInsertEditDelete_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
gridviewXMLInsertEditDelete.ShowFooter =
False
gridviewXMLInsertEditDelete.EditIndex = e.NewEditIndex
BindGridView()
End Sub
Protected Sub gridviewXMLInsertEditDelete_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim index As Integer = gridviewXMLInsertEditDelete.Rows(e.RowIndex).DataItemIndex
Dim Title As String = DirectCast(gridviewXMLInsertEditDelete.Rows(e.RowIndex).FindControl("txtTitle"), TextBox).Text
Dim Link As String = DirectCast(gridviewXMLInsertEditDelete.Rows(e.RowIndex).FindControl("txtLink"), TextBox).Text
Dim Description As String = DirectCast(gridviewXMLInsertEditDelete.Rows(e.RowIndex).FindControl("txtDescription"), TextBox).Text
gridviewXMLInsertEditDelete.EditIndex = -1
BindGridView()
Dim dsUpdateXMLFile As DataSet = DirectCast(gridviewXMLInsertEditDelete.DataSource, DataSet)
dsUpdateXMLFile.Tables(0).Rows(index)(
"Title") = Title
dsUpdateXMLFile.Tables(0).Rows(index)(
"Link") = Link
dsUpdateXMLFile.Tables(0).Rows(index)(
"Description") = Description
dsUpdateXMLFile.WriteXml(Server.MapPath(
"./App_Data/XMLFile.xml"))
BindGridView()
End Sub
Protected Sub gridviewXMLInsertEditDelete_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
gridviewXMLInsertEditDelete.EditIndex = -1
BindGridView()
End Sub
Protected Sub gridviewXMLInsertEditDelete_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "InsertXMLData" Then
Dim Title As String = DirectCast(gridviewXMLInsertEditDelete.FooterRow.FindControl("txtTitleInsert"), TextBox).Text
Dim Link As String = DirectCast(gridviewXMLInsertEditDelete.FooterRow.FindControl("txtLinkInsert"), TextBox).Text
Dim Description As String = DirectCast(gridviewXMLInsertEditDelete.FooterRow.FindControl("txtDescriptionInsert"), TextBox).Text
BindGridView()
Dim dsXMLInsert As DataSet = DirectCast(gridviewXMLInsertEditDelete.DataSource, DataSet)
Dim drInsert As DataRow = dsXMLInsert.Tables(0).NewRow()
drInsert(
"Title") = Title
drInsert(
"Link") = Link
drInsert(
"Description") = Description
dsXMLInsert.Tables(0).Rows.Add(drInsert)
dsXMLInsert.WriteXml(Server.MapPath(
"./App_Data/XMLFile.xml"))
BindGridView()
End If
End Sub
End
Class
v