J
James Norton-Jones
Hi,
Am I trying to hold the data of a DataGrid in a label so that when the form
is reposted the DataGrid can be repopulated. The problem I am having is that
I don't understand how to get the text into a stream in order to be able to
use DataSetOutcomes1.ReadXML(MyStream).
Thanks in advance,
James
Web Form:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="course_new.aspx.vb"
Inherits="_1137InsetBookingSystem.course_new"%>
<!-- #INCLUDE file="headeraspx.inc" -->
<!-- #INCLUDE file="tableheader.inc" -->
<form id="FormNewCourse" method="post" runat="server">
<table cellSpacing="0" cols="3" cellPadding="0" width="100%" border="0">
<tr>
<td vAlign="top"><asp:label id="lblCourseTitle" runat="server"
Font-Bold="True">Course Title</asp:label></td>
<td><asp:textbox id="txtCourseTitle" runat="server"></asp:textbox></td>
<td> </td>
</tr>
<tr>
<td colSpan="3"><asp:label id="lblCourseTutorList" runat="server"
Font-Bold="True">Course Tutor(s)</asp:label></td>
</tr>
<tr>
<td vAlign="top"> </td>
<td><asp:textbox id="txtCourseTutor" runat="server"></asp:textbox></td>
<td><asp:button id="cmdAdd" runat="server" Text="Add" BackColor="#F6CD7A"
BorderStyle="Solid" BorderWidth="1px"
Width="80px"></asp:button></td>
</tr>
<tr>
<td> </td>
<td><asp:textbox id="txtTutorList" runat="server" Rows="5"
TextMode="MultiLine"></asp:textbox></td>
<td> </td>
</tr>
<tr>
<td colSpan="3"><asp:label id="lblLearningOutcomes" runat="server"
Font-Bold="True">Learning Outcomes</asp:label></td>
</TD></tr>
<tr>
<td> </td>
<td><asp:textbox id="txtOutcome" runat="server"></asp:textbox></td>
<td><asp:button id="cmdAddOutcome" runat="server" Text="Add"
BackColor="#F6CD7A" BorderStyle="Solid"
BorderWidth="1px" Width="80px"
CausesValidation="False"></asp:button></td>
</tr>
<tr>
<td> </td>
<td><asp:datagrid id=DataGridOutcomes runat="server" GridLines="None"
AutoGenerateColumns="False" DataMember="Outcomes" DataSource="<%#
DatasetOutcomes1 %>">
<HeaderStyle Font-Bold="True"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<ul>
<li>
</li>
</ul>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Name" SortExpression="Name"
HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="DisplayOrder"
SortExpression="DisplayOrder" HeaderText="DisplayOrder"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete"
ButtonType="PushButton"></asp:ButtonColumn>
<asp:ButtonColumn Text="Edit"
ButtonType="PushButton"></asp:ButtonColumn>
</Columns>
</asp:datagrid></td>
<td> </td>
</tr>
<tr>
<td colSpan="3"><asp:label id="lblOutcomes"
runat="server"></asp:label></td>
</tr>
</table>
</form>
<!-- #INCLUDE file="tablefooter.inc" -->
<!-- #INCLUDE file="footer.inc" -->
Code Bind:
Imports System
Imports System.IO
Imports System.Xml
Public Class course_new
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DatasetOutcomes1 = New _1137InsetBookingSystem.DatasetOutcomes
CType(Me.DatasetOutcomes1,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'DatasetOutcomes1
'
Me.DatasetOutcomes1.DataSetName = "DatasetOutcomes"
Me.DatasetOutcomes1.Locale = New
System.Globalization.CultureInfo("en-GB")
CType(Me.DatasetOutcomes1,
System.ComponentModel.ISupportInitialize).EndInit()
End Sub
Protected WithEvents lblCourseTitle As System.Web.UI.WebControls.Label
Protected WithEvents txtCourseTitle As System.Web.UI.WebControls.TextBox
Protected WithEvents txtCourseTutor As System.Web.UI.WebControls.TextBox
Protected WithEvents txtTutorList As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdAdd As System.Web.UI.WebControls.Button
Protected WithEvents txtOutcome As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdAddOutcome As System.Web.UI.WebControls.Button
Protected WithEvents lblCourseTutorList As
System.Web.UI.WebControls.Label
Protected WithEvents lblLearningOutcomes As
System.Web.UI.WebControls.Label
Protected WithEvents DataGridOutcomes As
System.Web.UI.WebControls.DataGrid
Protected WithEvents DatasetOutcomes1 As
_1137InsetBookingSystem.DatasetOutcomes
Protected WithEvents lblOutcomes As System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public gstrTableTitle As String = "Create Course"
Public gstrTableAttribs As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.DataGridOutcomes.DataBind()
Else
Dim str As String = Me.lblOutcomes.Text
Dim MyStream As StreamReader
If str.Length > 0 Then
MyStream = New StreamReader(str)
Me.DatasetOutcomes1.ReadXml(MyStream)
End If
'Me.DatasetOutcomes1.GetXml()
'
End If
End Sub
Private Sub UpdateOutcomes()
Me.DataGridOutcomes.DataSource = Me.DatasetOutcomes1
Me.DataGridOutcomes.DataBind()
End Sub
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
If InStr(Me.txtTutorList.Text, Me.txtCourseTutor.Text) < 1 Then
If Me.txtTutorList.Text.Length > 0 Then
Me.txtTutorList.Text = Me.txtTutorList.Text & ";" & vbCrLf &
Me.txtCourseTutor.Text
Else
Me.txtTutorList.Text = Me.txtCourseTutor.Text
End If
End If
End Sub
Private Sub cmdAddOutcome_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdAddOutcome.Click
Dim dr As DatasetOutcomes.OutcomesRow
dr = Me.DatasetOutcomes1.Outcomes.NewRow()
dr.Item("Name") = Me.txtOutcome.Text
dr.Item("DisplayOrder") = Me.DatasetOutcomes1.Outcomes.Rows.Count
'DatasetOutcomes1.Outcomes.Rows.InsertAt(dr,
Me.DatasetOutcomes1.Outcomes.Rows.Count)
DatasetOutcomes1.Outcomes.Rows.Add(dr)
Me.DataGridOutcomes.DataBind()
Me.lblOutcomes.Text = Me.DatasetOutcomes1.GetXml
End Sub
End Class
Am I trying to hold the data of a DataGrid in a label so that when the form
is reposted the DataGrid can be repopulated. The problem I am having is that
I don't understand how to get the text into a stream in order to be able to
use DataSetOutcomes1.ReadXML(MyStream).
Thanks in advance,
James
Web Form:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="course_new.aspx.vb"
Inherits="_1137InsetBookingSystem.course_new"%>
<!-- #INCLUDE file="headeraspx.inc" -->
<!-- #INCLUDE file="tableheader.inc" -->
<form id="FormNewCourse" method="post" runat="server">
<table cellSpacing="0" cols="3" cellPadding="0" width="100%" border="0">
<tr>
<td vAlign="top"><asp:label id="lblCourseTitle" runat="server"
Font-Bold="True">Course Title</asp:label></td>
<td><asp:textbox id="txtCourseTitle" runat="server"></asp:textbox></td>
<td> </td>
</tr>
<tr>
<td colSpan="3"><asp:label id="lblCourseTutorList" runat="server"
Font-Bold="True">Course Tutor(s)</asp:label></td>
</tr>
<tr>
<td vAlign="top"> </td>
<td><asp:textbox id="txtCourseTutor" runat="server"></asp:textbox></td>
<td><asp:button id="cmdAdd" runat="server" Text="Add" BackColor="#F6CD7A"
BorderStyle="Solid" BorderWidth="1px"
Width="80px"></asp:button></td>
</tr>
<tr>
<td> </td>
<td><asp:textbox id="txtTutorList" runat="server" Rows="5"
TextMode="MultiLine"></asp:textbox></td>
<td> </td>
</tr>
<tr>
<td colSpan="3"><asp:label id="lblLearningOutcomes" runat="server"
Font-Bold="True">Learning Outcomes</asp:label></td>
</TD></tr>
<tr>
<td> </td>
<td><asp:textbox id="txtOutcome" runat="server"></asp:textbox></td>
<td><asp:button id="cmdAddOutcome" runat="server" Text="Add"
BackColor="#F6CD7A" BorderStyle="Solid"
BorderWidth="1px" Width="80px"
CausesValidation="False"></asp:button></td>
</tr>
<tr>
<td> </td>
<td><asp:datagrid id=DataGridOutcomes runat="server" GridLines="None"
AutoGenerateColumns="False" DataMember="Outcomes" DataSource="<%#
DatasetOutcomes1 %>">
<HeaderStyle Font-Bold="True"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<ul>
<li>
</li>
</ul>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Name" SortExpression="Name"
HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="DisplayOrder"
SortExpression="DisplayOrder" HeaderText="DisplayOrder"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete"
ButtonType="PushButton"></asp:ButtonColumn>
<asp:ButtonColumn Text="Edit"
ButtonType="PushButton"></asp:ButtonColumn>
</Columns>
</asp:datagrid></td>
<td> </td>
</tr>
<tr>
<td colSpan="3"><asp:label id="lblOutcomes"
runat="server"></asp:label></td>
</tr>
</table>
</form>
<!-- #INCLUDE file="tablefooter.inc" -->
<!-- #INCLUDE file="footer.inc" -->
Code Bind:
Imports System
Imports System.IO
Imports System.Xml
Public Class course_new
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DatasetOutcomes1 = New _1137InsetBookingSystem.DatasetOutcomes
CType(Me.DatasetOutcomes1,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'DatasetOutcomes1
'
Me.DatasetOutcomes1.DataSetName = "DatasetOutcomes"
Me.DatasetOutcomes1.Locale = New
System.Globalization.CultureInfo("en-GB")
CType(Me.DatasetOutcomes1,
System.ComponentModel.ISupportInitialize).EndInit()
End Sub
Protected WithEvents lblCourseTitle As System.Web.UI.WebControls.Label
Protected WithEvents txtCourseTitle As System.Web.UI.WebControls.TextBox
Protected WithEvents txtCourseTutor As System.Web.UI.WebControls.TextBox
Protected WithEvents txtTutorList As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdAdd As System.Web.UI.WebControls.Button
Protected WithEvents txtOutcome As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdAddOutcome As System.Web.UI.WebControls.Button
Protected WithEvents lblCourseTutorList As
System.Web.UI.WebControls.Label
Protected WithEvents lblLearningOutcomes As
System.Web.UI.WebControls.Label
Protected WithEvents DataGridOutcomes As
System.Web.UI.WebControls.DataGrid
Protected WithEvents DatasetOutcomes1 As
_1137InsetBookingSystem.DatasetOutcomes
Protected WithEvents lblOutcomes As System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public gstrTableTitle As String = "Create Course"
Public gstrTableAttribs As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.DataGridOutcomes.DataBind()
Else
Dim str As String = Me.lblOutcomes.Text
Dim MyStream As StreamReader
If str.Length > 0 Then
MyStream = New StreamReader(str)
Me.DatasetOutcomes1.ReadXml(MyStream)
End If
'Me.DatasetOutcomes1.GetXml()
'
End If
End Sub
Private Sub UpdateOutcomes()
Me.DataGridOutcomes.DataSource = Me.DatasetOutcomes1
Me.DataGridOutcomes.DataBind()
End Sub
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
If InStr(Me.txtTutorList.Text, Me.txtCourseTutor.Text) < 1 Then
If Me.txtTutorList.Text.Length > 0 Then
Me.txtTutorList.Text = Me.txtTutorList.Text & ";" & vbCrLf &
Me.txtCourseTutor.Text
Else
Me.txtTutorList.Text = Me.txtCourseTutor.Text
End If
End If
End Sub
Private Sub cmdAddOutcome_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdAddOutcome.Click
Dim dr As DatasetOutcomes.OutcomesRow
dr = Me.DatasetOutcomes1.Outcomes.NewRow()
dr.Item("Name") = Me.txtOutcome.Text
dr.Item("DisplayOrder") = Me.DatasetOutcomes1.Outcomes.Rows.Count
'DatasetOutcomes1.Outcomes.Rows.InsertAt(dr,
Me.DatasetOutcomes1.Outcomes.Rows.Count)
DatasetOutcomes1.Outcomes.Rows.Add(dr)
Me.DataGridOutcomes.DataBind()
Me.lblOutcomes.Text = Me.DatasetOutcomes1.GetXml
End Sub
End Class