D
DotNetJunkies User
I'm trying create a single page app that allows the user to enter text (Serial) via a form and submit and populate that value into a datagrid via a datatable.
It works for ONE value but each time a new row is added, it replaces the 1st.
Somehow I'm reinitalizing the table, but not sure what I'm doing wrong because I'm very new at this stuff.....
Thanks
Devon
:>
Code Here
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<script runat="server">
' Create a New Table
Dim tblNewBox As DataTable = new DataTable("tblNewBox")
Dim colSerialNO as DataColumn
Dim mydataSet as New Dataset()
Sub Page_Load(Sender As Object, E As EventArgs)
'Create a New Data Column in the Table
colSerialNO = New DataColumn()
colSerialNO.Datatype = System.Type.GetType("System.String")
colSerialNO.ColumnName = "SerialNo"
colSerialNO.ReadOnly = False
colSerialNO.Unique = False
tblNewBox.Columns.Add(colSerialNO)
myDataSet.Tables.Add(tblNewBox)
End Sub
Sub AddRow_Click_1(sender As Object, e As EventArgs)
'Create several Rows in the Table
Dim TempRow as DataRow
TempRow = tblNewBox.newRow()
TempRow.Item("SerialNo") = TextBox1.text
tblNewBox.Rows.Add(TempRow)
' Bind the Dataset to the Datagrid
DataGrid1.datasource = myDataSet
dataGrid1.Databind()
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p align="center">
</p>
<p align="center">
<font face="Arial" size="2"></font>
</p>
<p align="center">
<font face="Arial" size="2">
<br />
</font>
</p>
<p align="center">
<font face="Arial" size="2"></font>
</p>
<font face="Arial" size="2">
<p align="center">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button id="Button1" onclick="addRow_Click_1" runat="server" Text="Add Item to Table"></asp:Button>
</p>
<p align="center">
</p>
<p align="center">
<asp
ataGrid id="DataGrid1" runat="server" ForeColor="Black" CellPadding="2" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" GridLines="None">
<FooterStyle backcolor="Tan"></FooterStyle>
<HeaderStyle font-bold="True" backcolor="Tan"></HeaderStyle>
<PagerStyle horizontalalign="Center" forecolor="DarkSlateBlue" backcolor="PaleGoldenrod"></PagerStyle>
<SelectedItemStyle forecolor="GhostWhite" backcolor="DarkSlateBlue"></SelectedItemStyle>
<AlternatingItemStyle backcolor="PaleGoldenrod"></AlternatingItemStyle>
</asp
ataGrid>
</p>
</font>
</form>
</body>
</html>
It works for ONE value but each time a new row is added, it replaces the 1st.
Somehow I'm reinitalizing the table, but not sure what I'm doing wrong because I'm very new at this stuff.....
Thanks
Devon
:>
Code Here
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<script runat="server">
' Create a New Table
Dim tblNewBox As DataTable = new DataTable("tblNewBox")
Dim colSerialNO as DataColumn
Dim mydataSet as New Dataset()
Sub Page_Load(Sender As Object, E As EventArgs)
'Create a New Data Column in the Table
colSerialNO = New DataColumn()
colSerialNO.Datatype = System.Type.GetType("System.String")
colSerialNO.ColumnName = "SerialNo"
colSerialNO.ReadOnly = False
colSerialNO.Unique = False
tblNewBox.Columns.Add(colSerialNO)
myDataSet.Tables.Add(tblNewBox)
End Sub
Sub AddRow_Click_1(sender As Object, e As EventArgs)
'Create several Rows in the Table
Dim TempRow as DataRow
TempRow = tblNewBox.newRow()
TempRow.Item("SerialNo") = TextBox1.text
tblNewBox.Rows.Add(TempRow)
' Bind the Dataset to the Datagrid
DataGrid1.datasource = myDataSet
dataGrid1.Databind()
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p align="center">
</p>
<p align="center">
<font face="Arial" size="2"></font>
</p>
<p align="center">
<font face="Arial" size="2">
<br />
</font>
</p>
<p align="center">
<font face="Arial" size="2"></font>
</p>
<font face="Arial" size="2">
<p align="center">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button id="Button1" onclick="addRow_Click_1" runat="server" Text="Add Item to Table"></asp:Button>
</p>
<p align="center">
</p>
<p align="center">
<asp

<FooterStyle backcolor="Tan"></FooterStyle>
<HeaderStyle font-bold="True" backcolor="Tan"></HeaderStyle>
<PagerStyle horizontalalign="Center" forecolor="DarkSlateBlue" backcolor="PaleGoldenrod"></PagerStyle>
<SelectedItemStyle forecolor="GhostWhite" backcolor="DarkSlateBlue"></SelectedItemStyle>
<AlternatingItemStyle backcolor="PaleGoldenrod"></AlternatingItemStyle>
</asp

</p>
</font>
</form>
</body>
</html>