我有一个始终处于插入模式的详细信息视图。用户将始终只输入新记录,从不编辑或查看。我遇到的问题是当我按下插入按钮(在填写完字段后添加新记录)时没有任何反应。没有输入记录,页面显示没有变化。
由于回发和提交值的这些问题,我一直在研究这个细节视图并没有取得太大进展。任何帮助表示赞赏
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DetailsView1.DataBind();
}
}
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
ObjectDataSource1.DataBind();
DetailsView1.DataBind();
SqlDataSource1.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_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
DetailsView1.DataSource = null;
DetailsView1.DataBind();
}
protected void Button2_Click1(object sender, EventArgs e)
{
Button3.Visible = true;
}
protected void Button3_Click(object sender, EventArgs e)
{
DetailsView1.Visible = true;
DetailsView1.ChangeMode(DetailsViewMode.Insert);
if (DetailsView1.CurrentMode.Equals(DetailsViewMode.Insert))
{
Button3.Visible = false;
Button4.Visible = false;
DetailsView2.Visible = true;
DetailsView3.Visible = true;
}
}
protected void DropDownList5_SelectedIndexChanged1(object sender, EventArgs e)
{
}
protected void DropDownList6_DataBound(object sender, EventArgs e)
{
}
protected void DropDownList6_DataBound1(object sender, EventArgs e)
{
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
//null reference to the object
if (!IsPostBack)
{
string selectedValue = lvtype.SelectedValue;
if (selectedValue == "4 " || selectedValue == "1F")
{
SqlDataSource1.SelectParameters["LEAVECODE"].DefaultValue = selectedValue;
DetailsView1.Fields[4].Visible = true;
lvreason.Visible = true;
}
else
{
DetailsView1.Fields[4].Visible = false;
}
lvtype.Items.Add(new ListItem("EDUCATION LEAVE"));
lvtype.Items.Add(new ListItem("EXCUSED LEAVE"));
lvtype.Items.Add(new ListItem("FUNERAL LEAVE"));
lvtype.Items.Add(new ListItem("JURY DUTY"));
lvtype.Items.Add(new ListItem("ON THE JOB INJURY LEAVE"));
lvtype.Items.Add(new ListItem("PERSONAL HOLIDAY"));
lvtype.Items.Add(new ListItem("SICK LEAVE"));
lvtype.Items.Add(new ListItem("VACATION LEAVE"));
}
}
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();
//DetailsView1.Fields[4].Visible;
}
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();
}
}
}
asp代码:
<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>
<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>
<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>
<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>