我有一个dropdownlist
的页面附加了selectedIndexChanged
个事件。因此,对于dropdownlist
中的每个选项,都有一个usercontrol
,其中包含与该部分相关的表单。 (每个用户控件都在一个面板中,selectedIndexChanged
事件切换该面板的可见性。
但是,对于其中一个表单,我将数据插入到SQL Server中,因此使用了formview,只是问题是它没有插入。
花了很长时间剥离页面以找出失败点后,发现AutoPostBack="true
上的dropdownlist
“导致了问题。即使我删除所有其他内容面板/用户控件,并使其形成所有团队可见的formview面板(意味着dropdownlist
未被更改,因此没有发生回传)它仍然只是失败。如果我从下拉列表中删除它,数据插入没问题。
之前有没有人见过这个,或者可以想到为什么会发生这种情况的原因?
我会发布dropdown
的代码以防它有用:
<asp:Label ID="uxFormSwitchLabel" runat="server" Text="What would you like to do?" AssociatedControlID="uxFormSwitch" />
<asp:DropDownList ID="uxFormSwitch" runat="server" AutoPostBack="true" OnSelectedIndexChanged="uxFormSwitch_SelectedIndexChanged">
<asp:ListItem Value="Please Select" Text="Please Select" Selected="True" />
<asp:ListItem Value="Change my address" Text="Change my address" />
<asp:ListItem Value="Change my bank details" Text="Change my bank details" />
<asp:ListItem Value="Change my class of use" Text="Change my class of use" />
<asp:ListItem Value="Change my personal details" Text="Change my personal details" />
<asp:ListItem Value="Other" Text="Other" />
</asp:DropDownList>
更新 - 根据要求,这是formview插入的代码:
<asp:FormView ID="uxDriverByID" runat="server" DataKeyNames="DriverID" DefaultMode="Insert" DataSourceID="dsDriverByID" ondatabound="uxDriverByID_DataBound" oniteminserting="uxDriverByID_ItemInserting">
<InsertItemTemplate>
<asp:HiddenField ID="uxEntryType" runat="server" Value='<%# Bind("EntryType") %>' />
<asp:Label ID="uxDateLabel" runat="server" AssociatedControlID="uxDate" Text="Date cover is to begin"></asp:Label>
<asp:TextBox ID="uxDate" CssClass="datepicker" runat="server" Text='<%# Bind("StartDate") %>'></asp:TextBox>
<div class="clear"></div>
<asp:Label ID="uxEndDateLabel" runat="server" AssociatedControlID="uxEndDate" Text="Date cover is to begin"></asp:Label>
<asp:TextBox ID="uxEndDate" CssClass="datepicker" runat="server" Text='<%# Bind("EndDate") %>'></asp:TextBox>
<asp:Label ID="uxTitleLabel" runat="server" AssociatedControlID="uxTitle" Text="Title" ></asp:Label>
<asp:DropDownList ID="uxTitle" runat="server" SelectedValue='<%# Bind("Title") %>'>
<asp:ListItem Value="0" Text="Please Select" />
<asp:ListItem Value="1" Text="Mr" />
<asp:ListItem Value="2" Text="Mrs" />
<asp:ListItem Value="3" Text="Miss" />
<asp:ListItem Value="4" Text="Ms" />
<asp:ListItem Value="5" Text="Doctor" />
</asp:DropDownList>
<asp:Label ID="uxFirstNameLabel" runat="server" AssociatedControlID="uxFirstName" Text="First Name"></asp:Label>
<asp:TextBox ID="uxFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
<asp:Label ID="uxSurnameLabel" runat="server" AssociatedControlID="uxSurname" Text="Surname"></asp:Label>
<asp:TextBox ID="uxSurname" runat="server" Text='<%# Bind("Surname") %>'></asp:TextBox>
<asp:Label ID="uxDateOfBirthLabel" runat="server" AssociatedControlID="uxDay" Text="Date of birth"></asp:Label>
<div class="input">
<div class="dateofbirth">
<asp:DropDownList ID="uxDay" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="uxMonth" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="uxYear" runat="server">
</asp:DropDownList>
</div>
</div>
<asp:Label ID="uxGenderLabel" runat="server" AssociatedControlID="uxGender" Text="Gender"></asp:Label>
<div class="input">
<asp:DropDownList ID="uxGender" runat="server" SelectedValue='<%# Bind("Gender") %>'>
<asp:ListItem Value="0" Text="Please Select" />
<asp:ListItem Value="1" Text="Male" />
<asp:ListItem Value="2" Text="Female" />
</asp:DropDownList>
<asp:Label ID="uxRelationshipLabel" runat="server" AssociatedControlID="uxRelationship"
Text="Relationship to Proposer"></asp:Label>
<asp:DropDownList ID="uxRelationship" runat="server" SelectedValue='<%# Bind("Relationship") %>'>
<asp:ListItem Value="Please Select" Text="Please Select" />
<asp:ListItem Value="Spouse" Text="Spouse" />
<asp:ListItem Value="Common law partner" Text="Common law partner" />
<asp:ListItem Value="Leasing company" Text="Leasing company" />
<asp:ListItem Value="Parent" Text="Parent" />
<asp:ListItem Value="Company" Text="Company" />
<asp:ListItem Value="Other" Text="Other" />
</asp:DropDownList>
<div class="clear"></div>
<asp:Label ID="uxMaritalStatusLabel" runat="server" AssociatedControlID="uxMaritalStatus" Text="Marital Status"></asp:Label>
<asp:DropDownList ID="uxMaritalStatus" runat="server" SelectedValue='<%# Bind("MaritalStatus") %>'>
<asp:ListItem Value="Please Select" Text="Please Select" />
<asp:ListItem Value="Married" Text="Married" />
<asp:ListItem Value="Single" Text="Single" />
<asp:ListItem Value="Divorced" Text="Divorced" />
<asp:ListItem Value="Widowed" Text="Widowed" />
<asp:ListItem Value="Separated" Text="Separated" />
<asp:ListItem Value="Common Law" Text="Common Law" />
<asp:ListItem Value="Civil Partner" Text="Civil Partner" />
</asp:DropDownList>
<asp:Label ID="uxEmploymentStatusLabel" AssociatedControlID="uxEmploymentStatus" runat="server" Text="Employment Status"/>
<asp:DropDownList ID="uxEmploymentStatus" runat="server" SelectedValue='<%# Bind("EmploymentStatus") %>'>
<asp:ListItem Value="0" Text="Please Select" />
<asp:ListItem Value="1" Text="Employed" />
<asp:ListItem Value="2" Text="Self Employed" />
<asp:ListItem Value="3" Text="Retired" />
<asp:ListItem Value="4" Text="Household Duties" />
<asp:ListItem Value="5" Text="In Full or Part-time education" />
<asp:ListItem Value="6" Text="Unemployed" />
<asp:ListItem Value="7" Text="Company" />
<asp:ListItem Value="8" Text="Independent Means" />
<asp:ListItem Value="9" Text="Voluntary Work" />
</asp:DropDownList>
<asp:Label ID="uxOccupationLabel" AssociatedControlID="uxOccupation" runat="server" Text="Occupation" />
<asp:TextBox ID="uxOccupation" runat="server" Text='<%# Bind("Occupation") %>' />
<asp:Label ID="uxBusinessLabel" AssociatedControlID="uxBusiness" runat="server" Text="Employer's business" />
<asp:TextBox ID="uxBusiness" runat="server" Text='<%# Bind("Business") %>' />
<asp:Label ID="uxSecondaryEmploymentLabel" runat="server" AssociatedControlID="uxSecondaryEmployment" Text="Does this driver have a second occupation?"></asp:Label>
<asp:DropDownList ID="uxSecondaryEmployment" runat="server">
<asp:ListItem Value="" Text="Please Select" />
<asp:ListItem Value="No" Text="No" />
<asp:ListItem Value="Yes" Text="Yes" />
</asp:DropDownList>
<asp:Label ID="uxSecondaryEmploymentStatusLabel" AssociatedControlID="uxSecondaryEmploymentStatus" runat="server" Text="Secondary Employment Status" />
<asp:DropDownList ID="uxSecondaryEmploymentStatus" runat="server" SelectedValue='<%# Bind("SecondaryEmploymentStatus") %>'>
<asp:ListItem Value="0" Text="Please Select" />
<asp:ListItem Value="1" Text="Employed" />
<asp:ListItem Value="2" Text="Self Employed" />
<asp:ListItem Value="3" Text="Retired" />
<asp:ListItem Value="4" Text="Household Duties" />
<asp:ListItem Value="5" Text="In Full or Part-time education" />
<asp:ListItem Value="6" Text="Unemployed" />
<asp:ListItem Value="7" Text="Company" />
<asp:ListItem Value="8" Text="Independent Means" />
<asp:ListItem Value="9" Text="Voluntary Work" />
</asp:DropDownList>
<asp:Label ID="uxSecondaryOccupationLabel" AssociatedControlID="uxSecondaryOccupation" runat="server" Text="Secondary occupation" />
<asp:TextBox ID="uxSecondaryOccupation" runat="server" Text='<%# Bind("SecondaryOccupation") %>' />
<asp:Label ID="uxSecondaryBusinessLabel" AssociatedControlID="uxSecondaryBusiness" runat="server" Text="Employer's business" />
<asp:TextBox ID="uxSecondaryBusiness" runat="server" Text='<%# Bind("SecondaryBusiness") %>' />
<asp:Label ID="uxLicenceTypeLabel" runat="server" AssociatedControlID="uxLicenceType" Text="What type of licence does the driver hold?"></asp:Label>
<asp:DropDownList ID="uxLicenceType" runat="server" SelectedValue='<%# Bind("LicenceType") %>'>
<asp:ListItem Value="Please Select" Text="Please Select" />
<asp:ListItem Value="Full(UK)" Text="Full(UK)" />
<asp:ListItem Value="Provisional(UK)" Text="Provisional(UK)" />
<asp:ListItem Value="Foreign" Text="Foreign" />
<asp:ListItem Value="Restricted less than 3 years" Text="Restricted less than 3 years" />
<asp:ListItem Value="Restricted 3 years or over" Text="Restricted 3 years or over" />
</asp:DropDownList>
<asp:Label ID="uxTimeHeldLabel" runat="server" AssociatedControlID="uxTimeHeld" Text="How many years has the driver held this licence?"></asp:Label>
<asp:DropDownList ID="uxTimeHeld" runat="server" SelectedValue='<%# Bind("TimeHeld") %>'>
<asp:ListItem Value="0" Text="0" />
<asp:ListItem Value="1" Text="1" />
<asp:ListItem Value="2" Text="2" />
<asp:ListItem Value="3" Text="3" />
<asp:ListItem Value="4" Text="4" />
<asp:ListItem Value="5" Text="5" />
<asp:ListItem Value="6" Text="6" />
<asp:ListItem Value="7" Text="7" />
<asp:ListItem Value="8" Text="8" />
<asp:ListItem Value="9" Text="9 or over" />
</asp:DropDownList>
<asp:Label ID="uxClassSelectLabel" runat="server" AssociatedControlID="uxClassSelect" Text="What class of use do you want to change to?"></asp:Label>
<asp:DropDownList ID="uxClassSelect" runat="server" SelectedValue='<%# Bind("ClassSelect") %>'>
<asp:ListItem Value="Please Select" Text="Please Select" />
<asp:ListItem Value="1" Text="SDP - Includes Commuting if Required" />
<asp:ListItem Value="2" Text="Business Use Policy Holder In Person" />
<asp:ListItem Value="3" Text="Business Use Spouse In Person" />
<asp:ListItem Value="4" Text="usiness Use Policy Holder and Spouse" />
<asp:ListItem Value="5" Text="Policy Holder Business - Authorised Drivers" />
<asp:ListItem Value="6" Text="Commercial Travelling" />
</asp:DropDownList>
<asp:Label ID="uxConvictionsLabel" runat="server" AssociatedControlID="uxConvictions" Text="Has this driver had any motoring convictions in the last 5 years?"></asp:Label>
<asp:DropDownList ID="uxConvictions" runat="server" SelectedValue='<%# Bind("Convictions") %>'>
<asp:ListItem Value="" Text="Please Select" />
<asp:ListItem Value="No" Text="No" />
<asp:ListItem Value="Yes" Text="Yes" />
</asp:DropDownList>
<asp:Label ID="uxClaimsLabel" runat="server" AssociatedControlID="uxClaims" Text="Has this driver had any motoring claims in the last 5 years?"></asp:Label>
<div class="input">
<asp:DropDownList ID="uxClaims" runat="server" SelectedValue='<%# Bind("Claims") %>'>
<asp:ListItem Value="" Text="Please Select" />
<asp:ListItem Value="No" Text="No" />
<asp:ListItem Value="Yes" Text="Yes" />
</asp:DropDownList>
<asp:Label ID="uxResidentLabel" runat="server" AssociatedControlID="uxResident" Text="How many years has this driver been a permanent UK resident?"></asp:Label>
<asp:DropDownList ID="uxResident" runat="server" SelectedValue='<%# Bind("Resident") %>'>
<asp:ListItem Value="0" Text="0" />
<asp:ListItem Value="1" Text="1" />
<asp:ListItem Value="2" Text="2" />
<asp:ListItem Value="3" Text="3" />
<asp:ListItem Value="4" Text="4" />
<asp:ListItem Value="5" Text="5" />
<asp:ListItem Value="6" Text="6" />
<asp:ListItem Value="7" Text="7" />
<asp:ListItem Value="8" Text="8" />
<asp:ListItem Value="9" Text="9 or over" />
</asp:DropDownList>
<asp:Label ID="uxHowOftenLabel" runat="server" AssociatedControlID="uxHowOften" Text="How often will this driver use the vehicle?"></asp:Label>
<asp:DropDownList ID="uxHowOften" runat="server" SelectedValue='<%# Bind("HowOften") %>'>
<asp:ListItem Value="" Text="Please Select" />
<asp:ListItem Value="1" Text="Not Main User (frequent)" />
<asp:ListItem Value="2" Text="Main User" />
<asp:ListItem Value="3" Text="Infrequent (casual)" />
</asp:DropDownList>
<asp:Label ID="uxHomeownerLabel" runat="server" AssociatedControlID="uxHomeowner" Text="Is this driver a homeowner?"></asp:Label>
<asp:DropDownList ID="uxHomeowner" runat="server" SelectedValue='<%# Bind("Homeowner") %>'>
<asp:ListItem Value="" Text="Please Select" />
<asp:ListItem Value="No" Text="No" />
<asp:ListItem Value="Yes" Text="Yes" />
</asp:DropDownList>
<asp:Label ID="uxNumOfCarsLabel" runat="server" AssociatedControlID="uxNumOfCars" Text="Does this driver have access to any other cars within the household?" />
<asp:DropDownList ID="uxNumOfCars" runat="server" SelectedValue='<%# Bind("NumOfCars") %>'>
<asp:ListItem Value="0" Text="0" />
<asp:ListItem Value="1" Text="1" />
<asp:ListItem Value="2" Text="2" />
<asp:ListItem Value="3" Text="3" />
<asp:ListItem Value="4" Text="4" />
<asp:ListItem Value="5" Text="5" />
<asp:ListItem Value="6" Text="6" />
<asp:ListItem Value="7" Text="7" />
<asp:ListItem Value="8" Text="8" />
<asp:ListItem Value="9" Text="9 or over" />
</asp:DropDownList>
<div class="clear"></div>
<asp:Label ID="uxCarsOwnedLabel" runat="server" AssociatedControlID="uxCarsOwned" Text="Does this driver own any other cars?" />
<asp:DropDownList ID="uxCarsOwned" runat="server" SelectedValue='<%# Bind("CarsOwned") %>'>
<asp:ListItem Value="0" Text="0" />
<asp:ListItem Value="1" Text="1" />
<asp:ListItem Value="2" Text="2" />
<asp:ListItem Value="3" Text="3" />
<asp:ListItem Value="4" Text="4" />
<asp:ListItem Value="5" Text="5" />
<asp:ListItem Value="6" Text="6" />
<asp:ListItem Value="7" Text="7" />
<asp:ListItem Value="8" Text="8" />
<asp:ListItem Value="9" Text="9 or over" />
</asp:DropDownList>
<div class="clear"></div>
<asp:Label ID="uxClaimFreeLabel" runat="server" AssociatedControlID="uxClaimFree" Text="How many claim free years of driving other cars does this driver have" />
<asp:DropDownList ID="uxClaimFree" runat="server" SelectedValue='<%# Bind("ClaimFree") %>'>
<asp:ListItem Value="0" Text="0" />
<asp:ListItem Value="1" Text="1" />
<asp:ListItem Value="2" Text="2" />
<asp:ListItem Value="3" Text="3" />
<asp:ListItem Value="4" Text="4" />
<asp:ListItem Value="5" Text="5" />
<asp:ListItem Value="6" Text="6" />
<asp:ListItem Value="7" Text="7" />
<asp:ListItem Value="8" Text="8" />
<asp:ListItem Value="9" Text="9 or over" />
</asp:DropDownList>
<div class="clear"></div>
<asp:Label ID="uxRefusedLabel" runat="server" AssociatedControlID="uxRefused" Text="Has this driver ever had insurance refused, cancelled, premiums increased, or conditions imposed?"></asp:Label>
<asp:DropDownList ID="uxRefused" runat="server" SelectedValue='<%# Bind("Refused") %>'>
<asp:ListItem Value="" Text="Please Select" />
<asp:ListItem Value="No" Text="No" />
<asp:ListItem Value="Yes" Text="Yes" />
</asp:DropDownList>
<asp:Label ID="uxOtherConvictionsLabel" runat="server" AssociatedControlID="uxOtherConvictions" Text="Has this driver ever had any non-motoring criminal convictions or prosecutions pending?"></asp:Label>
<asp:DropDownList ID="uxOtherConvictions" runat="server" SelectedValue='<%# Bind("OtherConvictions") %>'>
<asp:ListItem Value="" Text="Please Select" />
<asp:ListItem Value="No" Text="No" />
<asp:ListItem Value="Yes" Text="Yes" />
</asp:DropDownList>
<asp:Label ID="uxDisabilityLabel" runat="server" AssociatedControlID="uxDisability" Text="Does this driver have any disability or medical condition that could affect their fitness to drive?"></asp:Label>
<asp:DropDownList ID="uxDisability" runat="server" SelectedValue='<%# Bind("Disability") %>'>
<asp:ListItem Value="" Text="Please Select" />
<asp:ListItem Value="No" Text="No" />
<asp:ListItem Value="Yes" Text="Yes" />
</asp:DropDownList>
<asp:Label ID="uxSubmitLabel" runat="server" AssociatedControlID="uxSubmit" Text="Submit"></asp:Label>
<asp:LinkButton ID="uxSubmit" runat="server" style="float:left" Text="Submit" CssClass="blue-button-ctrl med"
ValidationGroup="AddDriver" CausesValidation="true" CommandName="Insert" OnClick="uxSubmit_Click" />
<asp:LinkButton ID="uxUpdateButton" style="float:left" Text="Save changes"
runat="server" CssClass="blue-button-ctrl" Visible="false"
ValidationGroup="AddDriver" CausesValidation="true" />
<div class="clear"></div>
</InsertItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="dsDriverByID" runat="server" InsertMethod="DriverInsert" SelectMethod="GetByDriverID"
TypeName="GreenHomeDAL.DriverTableAdapters.DriverTableAdapter">
<InsertParameters>
<asp:Parameter Name="DriverType" Type="String" />
<asp:Parameter Name="SessionID" Type="String" />
<asp:Parameter Name="StartDate" Type="String" />
<asp:Parameter Name="EndDate" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
<asp:Parameter Name="DateOfBirth" Type="String" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="Relationship" Type="String" />
<asp:Parameter Name="MaritalStatus" Type="String" />
<asp:Parameter Name="EmploymentStatus" Type="String" />
<asp:Parameter Name="Occupation" Type="String" />
<asp:Parameter Name="Business" Type="String" />
<asp:Parameter Name="SecondaryEmploymentStatus" Type="String" />
<asp:Parameter Name="SecondaryOccupation" Type="String" />
<asp:Parameter Name="SecondaryBusiness" Type="String" />
<asp:Parameter Name="LicenceType" Type="String" />
<asp:Parameter Name="TimeHeld" Type="String" />
<asp:Parameter Name="ClassSelect" Type="String" />
<asp:Parameter Name="Convictions" Type="String" />
<asp:Parameter Name="Claims" Type="String" />
<asp:Parameter Name="Resident" Type="String" />
<asp:Parameter Name="HowOften" Type="String" />
<asp:Parameter Name="Homeowner" Type="String" />
<asp:Parameter Name="NumOfCars" Type="String" />
<asp:Parameter Name="CarsOwned" Type="String" />
<asp:Parameter Name="ClaimFree" Type="String" />
<asp:Parameter Name="Refused" Type="String" />
<asp:Parameter Name="OtherConvictions" Type="String" />
<asp:Parameter Name="Disability" Type="String" />
<asp:Parameter Name="DriverSession" Type="String" />
<asp:Parameter Name="EntryType" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
And the c# side:
protected void PopulateDateFields()
{
int startYear = 1900;
DropDownList uxDay = (DropDownList)uxDriverByID.FindControl("uxDay");
DropDownList uxMonth = (DropDownList)uxDriverByID.FindControl("uxMonth");
DropDownList uxYear = (DropDownList)uxDriverByID.FindControl("uxYear");
uxYear.Items.Clear();
uxMonth.Items.Clear();
uxDay.Items.Clear();
ListItem dayItem = new ListItem("DD", "0");
ListItem monthItem = new ListItem("MM", "0");
ListItem yearItem = new ListItem("YYYY", "0");
uxDay.Items.Add(dayItem);
uxMonth.Items.Add(monthItem);
uxYear.Items.Add(yearItem);
for (int i = (DateTime.Now.Year - 15); i >= startYear; i--)
{
uxYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
for (int i = 0; i < 12; i++)
{
string num = i.ToString();
if (num.Length == 1)
num = "0" + num;
string month = CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[i];
uxMonth.Items.Add(new ListItem(month, num));
}
for (int i = 1; i <= 31; i++)
{
string num = i.ToString();
if (num.Length == 1)
num = "0" + num;
uxDay.Items.Add(new ListItem(num, num));
}
uxDay.DataTextField = "Day";
uxDay.DataValueField = "Day";
uxMonth.DataTextField = "Month";
uxMonth.DataValueField = "Month";
uxYear.DataTextField = "Year";
uxYear.DataValueField = "Year";
}
我确实计划在ItemInserting事件中使用代码,但它只会将autopostback设置为false,因此还没有。
由于
答案 0 :(得分:1)
最后完全无关的答案,真的很莫名其妙。
我在autopostback下拉列表旁边有一个加载gif,它在CSS中设置为:
#loading_gif{
visibility:hidden;
}
在javascript中,我有这个功能:
function showLoading(id)
{
document.getElementById(id).style.visibility = 'visible';
setTimeout('document.images["loading-gif"].src="Assets/Images/eee-loader.gif"', 50);
}
当我将其更改为display:block
和display:none
,而不是visibility
时,表单视图插件才能完美运行。
好吧,它是固定的。如果有人能够阐明为什么会发生这种情况那么好,但只要它有效,那么我很高兴。感谢