我有一个具有多个字段的详细信息视图,并且始终仅在插入模式下使用。我遇到的问题是,当我将所有值输入到我的详细信息视图中并点击插入按钮时,没有任何反应。好吧,屏幕已刷新,但表中没有插入新记录。
这是我的 aspx 代码:
<td class="style2" colspan="2">
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="ObjectDataSource1" DataKeyNames="requestid"
Height="29px" Width="928px" AutoGenerateRows="False" CellPadding="4" ForeColor="#333333"
GridLines="None" Style="margin-right: 0px; text-align: left; margin-top: 0px;"
ondatabound="DetailsView1_DataBound"
onitemcommand="DetailsView1_ItemCommand"
oniteminserting="DetailsView1_ItemInserting" >
<Fields>
<asp:TemplateField AccessibleHeaderText="Request ID" HeaderText="Leave Request ID" Visible="False">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="Label19" runat="server" Text='<%# Bind("requestid") %>'></asp:Label>
<asp:TextBox ID="TextBox165" runat="server" Text='<%# bind("requestid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("requestid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Employee ID" HeaderText="Employee ID" >
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="Label21" runat="server" Text='<%# bind("emppid") %>'></asp:Label>
<asp:TextBox ID="TextBox17" runat="server" Text='<%# bind("emppid") %>'
></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# bind("emppid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Approver ID" HeaderText="Approver ID">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server" style="text-transform:uppercase;" DataSourceID="SqlDataSourceApprover"
DataTextField="APPROVNAME" DataValueField="APPROVERID"
SelectedValue='<%# Bind("approverid") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("approverid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Leave Type" SortExpression="reqleavecode">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server" Height="20px"
onselectedindexchanged="DropDownList6_SelectedIndexChanged" Width="171px"
ondatabound="DropDownList6_DataBound" AutoPostBack="True"
SelectedIndex='<%# bind("reqleavecode") %>'>
<asp:ListItem Text="-- SELECT LEAVE --" Value ="-1" Selected="True"></asp:ListItem>
<asp:ListItem Value="1E">EDUCATION LEAVE</asp:ListItem>
<asp:ListItem Value="1X">EXCUSED LEAVE</asp:ListItem>
<asp:ListItem Value="1F">FUNERAL LEAVE</asp:ListItem>
<asp:ListItem Value="1J">JURY DUTY</asp:ListItem>
<asp:ListItem Value="1N">ON THE JOB INJURY LEAVE</asp:ListItem>
<asp:ListItem Value="1P">PERSONAL HOLIDAY</asp:ListItem>
<asp:ListItem Value="4 ">SICK LEAVE</asp:ListItem>
<asp:ListItem Value="3">VACATION</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label26" runat="server" Text='<%# bind("reqleavecode") %>'></asp:Label>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("reqleavecode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Leave Type" HeaderText="Leave Reason"
Visible="False">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("leavetype") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="REASON"
DataValueField="REASON" Height="19px"
onselectedindexchanged="DropDownList5_SelectedIndexChanged1"
SelectedValue='<%# Bind("leavetype") %>' Width="163px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1Reason" runat="server"
ControlToValidate="DropDownList5" ErrorMessage="*Leave Reason Required"
ForeColor="Red"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="start date" HeaderText="Leave Date">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox5" runat="server"
Text='<%# Bind("lstdate", "{0:MM/dd/yyyy}") %>' Height="21px"
Width="67px"></asp:TextBox>
<asp:CalendarExtender ID="TextBox5_CalendarExtender" runat="server" Enabled="True"
TargetControlID="TextBox5">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox5" ErrorMessage="*Leave Date Required"
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:CompareValidator ID="CompareValidator18" runat="server"
ControlToCompare="TextBox7" ControlToValidate="TextBox5"
ErrorMessage="Leave date cannot be after start date" ForeColor="Red"
Operator="LessThanEqual" ToolTip="Must choose start date before end date"></asp:CompareValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("lenddate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="lenddate" HeaderText="Return Date">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox7" runat="server"
Text='<%# Bind("lenddate", "{0:MM/dd/yyyy}") %>' Height="21px"
Width="67px"></asp:TextBox>
<asp:CalendarExtender ID="TextBox7_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox7">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox7" ErrorMessage="*Return Date Required"
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox5" ControlToValidate="TextBox7"
ErrorMessage="Return date cannot be before start date" ForeColor="Red"
Operator="GreaterThanEqual"></asp:CompareValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label15" runat="server" Text='<%# Bind("lsttime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Leave Time" HeaderText="Leave Time">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox15" runat="server" Text='<%# Bind("lsttime") %>' Width="85px"
Height="22px" ToolTip="Type 'A' or 'P' to switch AM/PM"></asp:TextBox>
<asp:MaskedEditExtender ID="TextBox15_MaskedEditExtender" runat="server" TargetControlID="TextBox15"
Mask="99:99" MaskType="Time" AcceptAMPM="True" ErrorTooltipEnabled="True"
CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox15" ErrorMessage="*Invalid Time" ForeColor="Red"
ValidationExpression="^((([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[0-9]|1[0-9]|2[0-3])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?))$"></asp:RegularExpressionValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("lendtime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Return Time" HeaderText="Return Time">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("lsttime") %>' Width="85px"
Height="22px" ToolTip="Type 'A' or 'P' to switch AM/PM"></asp:TextBox>
<asp:MaskedEditExtender ID="TextBox8_MaskedEditExtender" runat="server"
AcceptAMPM="True" CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"
ErrorTooltipEnabled="True" Mask="99:99" MaskType="Time"
TargetControlID="TextBox8" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator10"
runat="server" ControlToValidate="TextBox8" ErrorMessage="*Invalid Time"
ForeColor="Red"
ValidationExpression="^((([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[0-9]|1[0-9]|2[0-3])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?))$"></asp:RegularExpressionValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("standby") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Standby" HeaderText="On Standby">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource10"
DataTextField=""Y/N"" DataValueField=""Y/N"" SelectedValue='<%# BIND("standby") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("rsndecline") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Reason Decline"
HeaderText="Request Decline Reason" InsertVisible="False">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox12" runat="server" Text='<%# Bind("rsndecline") %>'
Visible="False"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Status" HeaderText="Request Status" InsertVisible="False">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox13" runat="server" Text='<%# Bind("status") %>' Visible="False"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label14" runat="server" Text='<%# Bind("empremarks") %>'
ToolTip="Additional information pertaining to leave request"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="empremarks" HeaderText="Leave Request Remarks">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox14" runat="server" style="text-transform:uppercase;" Text='<%# Bind("empremarks") %>'
TextMode="MultiLine" Height="47px" Width="452px"
ToolTip="Additional information pertaining to leave request."></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="False"
CommandName="Edit" Height="21px" Text="Edit" Width="65px" />
<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="New" Height="21px" Text="New" Width="65px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Insert"
Text="Submit Request" />
<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="Cancel" Height="21px" onclick="Button2_Click1" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("lstdate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
</td>
</tr>
<tr>
<td class="style2" colspan="2">
<asp:Button ID="Button3" runat="server" Height="21px" onclick="Button3_Click"
Text="With Pay Leave Request" />
<asp:Button ID="Button4" runat="server" Height="21px" onclick="Button4_Click"
Text="Without Pay Leave Request" style="margin-left: 13px" Width="221px" />
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT REASON, LEAVECODE FROM LEAVRSN">
<SelectParameters>
<asp:Parameter Name="LEAVECODE" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SQLLEAVECODE" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT LEAVETYPE, LEAVECODE FROM LVTYPE ORDER BY LEAVECODE">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceApprover" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT APPROVERID, APPROVNAME FROM APPROVER ORDER BY APPROVERID">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource10" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT * FROM YNSELECT ORDER BY ALPH"></asp:SqlDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1111" runat="server">
</asp:ObjectDataSource>
<br />
<asp:Label ID="Label17" runat="server" ForeColor="#999999"
Text="Exhibit B PP-8"></asp:Label>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteRequestForm"
InsertMethod="InsertRequestForm" SelectMethod="SelectRequestEMPID" TypeName="DataHandler.DataHandler"
UpdateMethod="UpdateRequestFormLastName" OldValuesParameterFormatString="original_{0}">
<DeleteParameters>
<asp:Parameter Name="requestid" Type="Int64" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="requestid" Type="Int64" />
<asp:Parameter Name="emppid" Type="Decimal" />
<asp:Parameter Name="leavetype" Type="String" />
<asp:Parameter Name="lstdate" Type="DateTime" />
<asp:Parameter Name="lenddate" Type="DateTime" />
<asp:Parameter Name="lsttime" Type="String" />
<asp:Parameter Name="lendtime" Type="String" />
<asp:Parameter Name="standby" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="rsndecline" Type="String" />
<asp:Parameter Name="empremarks" Type="String" />
<asp:Parameter Name="approverid" Type="String" />
<asp:Parameter Name="reqleavecode" Type="Int32" />
</InsertParameters>
<SelectParameters>
<%-- <asp:Parameter Name="emppid" Type="Decimal" />--%>
<asp:QueryStringParameter Name="emppid" QueryStringField="emppid" Type="Decimal" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="requestid" Type="Int64" />
<asp:Parameter Name="emppid" Type="Decimal" />
<asp:Parameter Name="leavetype" Type="String" />
<asp:Parameter Name="lstdate" Type="DateTime" />
<asp:Parameter Name="lenddate" Type="DateTime" />
<asp:Parameter Name="lsttime" Type="String" />
<asp:Parameter Name="lendtime" Type="String" />
<asp:Parameter Name="requesreason" Type="String" />
<asp:Parameter Name="standby" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="rsndecline" Type="String" />
<asp:Parameter Name="empremarks" Type="String" />
<asp:Parameter Name="approverid" Type="String" />
<asp:Parameter Name="LASTNAME" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="SelectNameEmployeeForm"
TypeName="DataHandler.DataHandler">
<SelectParameters>
<asp:Parameter Name="empid" Type="Decimal" />
<asp:Parameter Name="firstname" Type="String" />
<asp:Parameter Name="lastname" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label ID="Label27" runat="server" ></asp:Label>
</asp:Content>
我背后的代码:
public partial class newRequestForm : System.Web.UI.Page
{
public string lvtype;
public string lvrequest;
private DataSet GetData()
{
ConnectionStringSettingsCollection cssc = ConfigurationManager.ConnectionStrings;
var sql = "SELECT LEAVETYPE, LEAVECODE FROM TESTBWTIME.BWLVTYPE ORDER BY LEAVECODE";
using (iDB2Connection conn = new iDB2Connection(GetConnectionString()))
{
conn.Open();
using (iDB2Command cmd = new iDB2Command(sql, conn))
{
cmd.DeriveParameters();
using (iDB2DataAdapter da = new iDB2DataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}
}
private String GetConnectionString()
{
ConnectionStringSettingsCollection cssc = ConfigurationManager.ConnectionStrings;
return cssc["connStringNET"].ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DetailsView1.DataBind();
}
}
protected void DetailsView1_DataBound(object sender, EventArgs e)
{
TextBox employeeID = (TextBox)(DetailsView1.FindControl("TextBox17"));
DropDownList approverID = (DropDownList)(DetailsView1.FindControl("DropDownList4"));
if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
var CurrUser = "";
Account.Login uusr = new Account.Login();
CurrUser = uusr.User.Identity.Name.ToString().ToUpper();
employeeID.Text = CurrUser.Substring(3, 3);
string supusrid = "";
DataHandler.DataHandler Dt = new DataHandler.DataHandler();
supusrid = Dt.SelectRequestApproverForm(supusrid);
approverID.SelectedValue = supusrid;
}
}
protected void DropDownList6_DataBound1(object sender, EventArgs e)
{
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
string selectedValue = lvtype.SelectedValue.ToString().ToUpper();
if (selectedValue == "4 " || selectedValue == "1F")
{
SqlDataSource1.SelectParameters["LEAVECODE"].DefaultValue = selectedValue;
DetailsView1.Fields[4].Visible = true;
lvreason.Visible = true;
}
else
{
DetailsView1.Fields[4].Visible = false;
}
}
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));
if (lvtype.SelectedValue != "")
{
if (lvtype.SelectedValue == "3 ")
{
lvreason.Text.Equals("VACATION").ToString().Trim().ToUpper();
lvtype.Text.Equals("VACATION").ToString().Trim().ToUpper();
}
else if (lvtype.SelectedValue == "1E")
{
lvreason.Text.Equals("EDUCATION LEAVE").ToString().Trim().ToUpper();
lvtype.Text.Equals("EDUCATION LEAVE").ToString().Trim().ToUpper();
}
else if (lvtype.SelectedValue == "1N")
{
lvreason.Text.Equals("ON THE JOB INJURY LEAVE").ToString().Trim().ToUpper();
lvtype.Text.Equals("ON THE JOB INJURY LEAVE").ToString().Trim().ToUpper();
}
else if (lvtype.SelectedValue == "1J")
{
lvreason.Text.Equals("JURY DUTY").ToString().Trim().ToUpper();
lvtype.Text.Equals("JURY DUTY").ToString().Trim().ToUpper();
}
else if (lvtype.SelectedValue == "1X")
{
lvreason.Text.Equals("EXCUSED LEAVE").ToString().Trim().ToUpper();
lvtype.Text.Equals("EXCUSED LEAVE").ToString().Trim().ToUpper();
}
else if (lvtype.SelectedValue == "1P")
{
lvreason.Text.Equals("PERSONAL HOLIDAY").ToString().Trim().ToUpper();
lvtype.Text.Equals("PERSONAL HOLIDAY").ToString().Trim().ToUpper();
}
}
}