这是我的整个网络表格,所以你可以看到我做了什么。我希望能够将 generatePassword(6) 的值放入: InsertCommand="INSERT INTO utcasesTest(created_by_user_id, status_id, criticality_id, project_id, case_num, ... 我的 db 表中的字段。
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
'Our Function generatePassword accepts one parameter 'passwordLength'
'passwordLength will obviously determine the password length.
'The aplhanumeric character set is assigned to the variable sDefaultChars
Function generatePassword(passwordLength)
'Declare variables
Dim sDefaultChars
Dim iCounter
Dim sMyPassword
Dim iPickedChar
Dim iDefaultCharactersLength
Dim iPasswordLength
'Initialize variables
sDefaultChars = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789"
iPasswordLength = passwordLength
iDefaultCharactersLength = Len(sDefaultChars)
Randomize() 'initialize the random number generator
'Loop for the number of characters password is to have
For iCounter = 1 To iPasswordLength
'Next pick a number from 1 to length of character set
iPickedChar = Int((iDefaultCharactersLength * Rnd) + 1)
'Next pick a character from the character set using the random number iPickedChar
'and Mid function
sMyPassword = sMyPassword & Mid(sDefaultChars, iPickedChar, 1)
Next
generatePassword = sMyPassword
End Function
</script>
<script runat="server" type="text/vb">
Sub FormView1_Item_Inserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
Response.Redirect("ThankYou.asp")
End Sub
Protected Sub FormView1_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.FormViewPageEventArgs)
End Sub
Protected Sub SqlDataSource1_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<!-- Input Form-->
<form id="form1" runat="server" method="post">
<div>
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="case_id"
DataSourceID="SqlDataSource_OC"
DefaultMode="Insert"
OnItemInserted="formview1_Item_Inserted"
onpageindexchanging="FormView1_PageIndexChanging">
<InsertItemTemplate>
<table>
<tr>
<td>criticality_id:</td>
<td>
<asp:DropDownList ID="criticality_idTextBox"
runat="server"
Text='<%# Bind("txt_criticality_id","{0:D}") %>'
DataSourceID="SqlDataSource_Criticality"
DataTextField="ut_value"
DataValueField="criticality_id"
AppendDataBoundItems="true">
<asp:ListItem Value="0"
Text="--Select Level--"
Selected="True" />
</asp:DropDownList>
<br />
</td>
</tr>
<tr>
<td>case_num:</td>
<td>
<asp:TextBox Name="txt_case_num"
ID="case_numTextBox"
runat="server"
Text='<%# Bind("txt_case_num") %>' /> **<------ This is the textbox the value needs to go into. It will be hidden so the user wont see it**
<br />
</td>
</tr>
<tr>
<td>title:</td>
<td>
<asp:TextBox ID="titleTextBox"
runat="server"
Text='<%# Bind("txt_title") %>' />
<br />
</td>
</tr>
<tr>
<td>description:</td>
<td>
<asp:TextBox ID="descriptionTextBox"
runat="server"
Text='<%# Bind("txt_description") %>' TextMode="MultiLine" />
<br />
</td>
</tr>
<tr>
<td>external_email_address:</td>
<td>
<asp:TextBox ID="external_email_addressTextBox"
runat="server"
Text='<%# Bind("txt_external_email_address") %>' />
<br />
</td>
</tr>
</table>
<asp:LinkButton ID="InsertButton"
runat="server"
CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton"
runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
<!--Datasource-->
<asp:SqlDataSource ID="SqlDataSource_OC"
runat="server"
ConnectionString="<%$ ConnectionStrings:OC_ConnectionString %>"
InsertCommand="INSERT INTO utcasesTest(created_by_user_id, status_id, criticality_id, project_id, case_num, is_active, description, title, created_by_timestamp, modified_by_timestamp, modified_by_user_id, is_external, external_email_address, object_id, object_type_id) VALUES (@txt_created_by_user_id, @txt_status_id, @txt_criticality_id, @txt_project_id, @txt_case_num, @txt_case_num **<-------This is where the value is passed to the DB**, @txt_description, @txt_title, getdate(), getdate(), @txt_modified_by_user_id, @txt_is_external, @txt_external_email_address, @txt_object_id, @txt_object_type_id)"
SelectCommand="SELECT utcasesTest.* FROM utcasesTest">
<InsertParameters>
<asp:Parameter Name="txt_created_by_user_id" DefaultValue="1" />
<asp:Parameter Name="txt_status_id" DefaultValue="1" />
<asp:Parameter Name="txt_criticality_id" />
<asp:Parameter Name="txt_project_id" DefaultValue="1" />
<asp:Parameter Name="txt_case_num" /> **<----------Paramater Definition**
<asp:Parameter Name="txt_is_active" DefaultValue="Y" />
<asp:Parameter Name="txt_description" />
<asp:Parameter Name="txt_title" />
<asp:Parameter Name="txt_created_by_timestamp" />
<asp:Parameter Name="txt_modified_by_timestamp" />
<asp:Parameter Name="txt_modified_by_user_id" DefaultValue="1" />
<asp:Parameter Name="txt_is_external" DefaultValue="Y" />
<asp:Parameter Name="txt_external_email_address" />
<asp:Parameter Name="txt_object_id" DefaultValue="-1" />
<asp:Parameter Name="txt_object_type_id" DefaultValue="-1" />
</InsertParameters>
</asp:SqlDataSource>
<!--Data source for criticallity dropdown-->
<!--Change Project ID to select criticality from right Binder: id 3 = GNRM-->
<asp:SqlDataSource ID="SqlDataSource_Criticality"
runat="server"
ConnectionString="<%$ ConnectionStrings:OCConnectionString_utcriticality %>"
SelectCommand="SELECT project_id, ut_value, criticality_id FROM utcriticality WHERE (project_id = 3)"
onselecting="SqlDataSource1_Selecting">
</asp:SqlDataSource>
<!--End data source for criticallity dropdown-->
</div>
</form>
</body>
</html>