📄 masters.aspx
字号:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Register TagPrefix="Hersh" Namespace="Generic" Assembly="GenEditAdd" %>
<%@Page Language="VB" %>
<html>
<script language="VB" runat="server">
Dim myConnection As OleDbConnection
Dim myCommand As OleDbDataAdapter
Dim ds As New DataSet
Dim ConnStr As String
Dim SQL As String
Sub Page_Load(Source As Object, E As EventArgs)
ConnStr = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=ASPNET;User ID=sa;"
myConnection = New OleDbConnection(ConnStr)
if NOT (isPostBack)
rebind
end if
End Sub
Sub ReBind()
'DataSetCommand
SQL = "select m.*, g.code_display as category "
SQL = SQL + "from masters m, groups g "
SQL = SQL + " where m.code_category = g.code_value"
myCommand = New OleDbDataAdapter(SQL, myConnection)
'use Fill method of DataSetCommand to populate dataset
myCommand.Fill(ds, "masters")
'Binding a Grid
Grid1.DataSource=ds.Tables("masters").DefaultView
Grid1.DataBind()
End Sub
Sub RunSql(sql as string)
'RC Change: Needs to be commented out
'Catch Control Validator errors
'if not page.isvalid then
'response.write("Stored Procedure did not execute")
'rebind
'exit sub
'end if
try
'sql = "Execute p_test " + vkey
Dim mycommand2 As New OleDbCommand(sql,myConnection)
myConnection.Open()
myCommand2.ExecuteNonQuery()
myConnection.Close()
'turn off editing
Grid1.EditItemIndex = -1
'Message.Text = "<b>Record Updated</b>"
Catch ex As OleDbException
' SQL error
Dim errItem As OleDbError
Dim errString As String
For Each errItem In ex.Errors
errString += ex.Message + "<br/>"
Next
Response.write( "SQL Error.Details follow:<br/><br/>" & errString)
catch myException as Exception
Response.Write("Exception: " + myException.ToString())
end try
rebind
End sub
Sub Grid1_delete(sender As Object, e As DataGridCommandEventArgs)
Dim code_value as string = Grid1.DataKeys.Item(E.Item.ItemIndex).ToString
Dim sql as string
sql = "Delete from masters where code_value = " + cstr(code_value)
RunSql(sql)
end sub
</script>
<head>
<title>Masters DataGrid 1</title>
</head>
<body>
<br>
<form runat=server>
<b>Chart of Accounts:</b><br>
<table width="95%">
<tr>
<td valign="top">
<asp:DataGrid id="Grid1" runat="server"
AutoGenerateColumns="false"
BackColor="White"
BorderWidth="1px" BorderStyle="Solid" BorderColor="Tan"
CellPadding="2" CellSpacing="0"
Font-Name="Verdana" Font-Size="8pt"
OnDeleteCommand = "Grid1_delete"
DataKeyField="code_value"
>
<Columns>
<asp:HyperLinkColumn Text="Edit" DataNavigateUrlField="code_value"
DataNavigateUrlFormatString="config_masters.aspx?code_value={0}"/>
<asp:HyperLinkColumn Text="Add" DataNavigateUrlField="code_value"
DataNavigateUrlFormatString="config_masters.aspx?code_value=0"/>
<asp:ButtonColumn Text="Delete" CommandName="Delete" HeaderText="Delete"/>
<asp:BoundColumn HeaderText="Account" DataField="code_display">
<HeaderStyle Width="150px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Group" DataField="category">
<HeaderStyle Width="150px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Type" DataField="type">
<HeaderStyle Width="150px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Opening" DataField="opening">
<HeaderStyle Width="150px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Closing" DataField="closing" >
<HeaderStyle Width="50px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<HeaderStyle BackColor="DarkRed" ForeColor="White" Font-Bold="true" >
</HeaderStyle>
<ItemStyle ForeColor="DarkSlateBlue">
</ItemStyle>
<AlternatingItemstyle BackColor="Beige">
</AlternatingItemstyle>
</asp:DataGrid>
</td></tr></table>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -