在我的详细信息视图上按下提交按钮后,我收到此错误,该视图有两个数据绑定下拉列表。我不在代码中的任何地方使用Eval或XPath,但经常使用Bind。
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Source Error:
[No relevant source lines]
Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\9b1781c5\212dfe37\App_Web_newrequestform.aspx.1420f3bc.0khdma4p.0.cs Line: 0
Stack Trace:
[InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.]
System.Web.UI.Page.GetDataItem() +2802118
ASP.authorized_leaverequest_newrequestform_aspx.__DataBinding__control69(Object sender, EventArgs e) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\9b1781c5\212dfe37\App_Web_newrequestform.aspx.1420f3bc.0khdma4p.0.cs:0
System.Web.UI.Control.OnDataBinding(EventArgs e) +91
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +14
System.Web.UI.WebControls.ListControl.PerformSelect() +34
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +29
System.Web.UI.Control.PreRenderRecursiveInternal() +103
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
反汇编指向---> mov dword ptr [ebp-58h],eax
我一直在搜索这个错误好几天没有运气。我已经尝试了WEBSWAPP以及搜索了许多论坛。请帮忙。
我正在尝试使用下拉列表让用户选择值来填充数据库。我的表单中的每个字段都是模板并且是数据绑定的。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
namespace TimeAndAttendanceUI.Authorized.LeaveRequest
{
public partial class newRequestForm : System.Web.UI.Page
{
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_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
string selectedValue = lvtype.SelectedValue.ToString().ToUpper();
if (selectedValue == "4 " || selectedValue == "1F")
{
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));
SqlDataSource1.SelectParameters["LEAVECODE"].DefaultValue = selectedValue;
lvreason.Visible = true;
}
}
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;
}
}
}
}
很抱歉用代码轰炸。
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:Label ID="HoursLabel" runat="server"></asp:Label>
<br />
<table class="style1">
<tr>
<td class="style2" colspan="2">
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="ObjectDataSource1" DataKeyNames="bwrequestid"
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"
oniteminserted="DetailsView1_ItemInserted"
onitemcommand="DetailsView1_ItemCommand" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" Width="180px" />
<Fields>
<asp:TemplateField AccessibleHeaderText="Request ID" HeaderText="Leave Request ID" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label18" runat="server" Text='<%# Bind("bwrequestid") %>'></asp:Label>
<asp:TextBox ID="TextBox169" runat="server" Text='<%# bind("bwrequestid") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="Label19" runat="server" Text='<%# Bind("bwrequestid") %>'></asp:Label>
<asp:TextBox ID="TextBox165" runat="server" Text='<%# bind("bwrequestid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("bwrequestid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Employee ID" HeaderText="Employee ID" >
<EditItemTemplate>
<asp:Label ID="Label20" runat="server" Text='<%# bind("emppid") %>'></asp:Label>
</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>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("approverid") %>' Height="21px"
Width="68px"></asp:TextBox>
</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>
<asp:DropDownList ID="DropDownList7" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SQLLEAVECODE"
style="text-transform:uppercase;" DataTextField="LEAVETYPE"
DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
SelectedValue='<%# BIND("REQLEAVECODE") %>' ViewStateMode="Enabled"
Width="165px" Height="19px">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server" DataSourceID="SQLLEAVECODE"
DataTextField="LEAVETYPE" style="text-transform:uppercase;" DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="166px" Height="19px"><asp:ListItem></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>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("leavetype") %>' Height="21px"
Width="43px"></asp:TextBox>
</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>
<asp:TextBox ID="TextBox5" runat="server"
Text='<%# Bind("lstdate", "{0:MM/dd/yyyy}") %>' Height="21px"
Width="72px"></asp:TextBox>
<asp:CalendarExtender ID="TextBox5_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox5">
</asp:CalendarExtender>
</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>
<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>
</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: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>
<asp:TextBox ID="TextBox15" runat="server" Height="21px"
Text='<%# Bind("lsttime") %>' ToolTip="Type 'A' or 'P' to switch AM/PM"
Width="85px"></asp:TextBox>
<asp:MaskedEditExtender ID="TextBox15_MaskedEditExtender" runat="server"
AcceptAMPM="True" CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"
ErrorTooltipEnabled="True" Mask="99:99" MaskType="Time"
TargetControlID="TextBox15" />
</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>
</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>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("lendtime") %>' Width="85px"></asp:TextBox>
</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" />
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("standby") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Standby" HeaderText="On Standby">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("standby") %>' MaxLength="1" Width="21px"></asp:TextBox>
</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>
<asp:TextBox ID="TextBox12" style="text-transform:uppercase;" runat="server" Text='<%# Bind("rsndecline") %>'
Visible="False"></asp:TextBox>
</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>
<asp:TextBox ID="TextBox13" runat="server" Text='<%# Bind("status") %>'></asp:TextBox>
</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>
<asp:TextBox ID="TextBox14" runat="server" style="text-transform:uppercase;" Text='<%# Bind("empremarks") %>'
TextMode="MultiLine" Height="50px" Width="449px"
ToolTip="Additional information pertaining to leave request"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox14" Display="Dynamic" Enabled="False"
ErrorMessage="*Leave Remarks Required for "Other" selection"
ForeColor="Red"></asp:RequiredFieldValidator>
</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>
<asp:Button ID="Button1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</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>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT REASON, LEAVECODE FROM BWLEAVRSN">
<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 BWLVTYPE ORDER BY LEAVECODE">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceApprover" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT APPROVERID, APPROVNAME FROM BWAPPROVER ORDER BY APPROVERID">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource10" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT * FROM BWYNSELECT ORDER BY ALPH"></asp:SqlDataSource>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label ID="Label27" runat="server" ></asp:Label>
</asp:Content>
答案 0 :(得分:4)
我注意到的一件事,我怀疑复制和粘贴在某种程度上是缺失的,因为缺少第一个 。我不认为它编译所以我猜你的代码中不存在。但是,值得检查。
您的错误可能是由SqlDataSource
内的TemplateField
引起的。移动DetailsView
之外的那些并给它一个旋转。
<强>之前强>
<asp:DetailsView ....
....
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server" style="text-transform:uppercase;" DataSourceID="SqlDataSourceApprover"
DataTextField="APPROVNAME" DataValueField="APPROVERID"
SelectedValue='<%# Bind("approverid") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceApprover" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT APPROVERID, APPROVNAME FROM BWAPPROVER ORDER BY APPROVERID">
</asp:SqlDataSource>
</InsertItemTemplate>
....
<EditItemTemplate>
<asp:DropDownList ID="DropDownList7" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SQLLEAVECODE"
style="text-transform:uppercase;" DataTextField="LEAVETYPE"
DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
SelectedValue='<%# BIND("REQLEAVECODE") %>' ViewStateMode="Enabled"
Width="165px" Height="19px">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server" DataSourceID="SQLLEAVECODE"
DataTextField="LEAVETYPE" style="text-transform:uppercase;" DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="166px" Height="19px"><asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SQLLEAVECODE" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT LEAVETYPE, LEAVECODE FROM BWLVTYPE ORDER BY LEAVECODE">
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="REASON"
DataValueField="REASON" Height="19px"
onselectedindexchanged="DropDownList5_SelectedIndexChanged1"
SelectedValue='<%# Bind("leavetype") %>' Visible="False" Width="163px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT REASON, LEAVECODE FROM BWLEAVRSN">
<SelectParameters>
<asp:ControlParameter ControlID="Label27" Name="LEAVECODE" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
....
</asp:DetailsView>
<强>后强>
<asp:DetailsView ....
....
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server" style="text-transform:uppercase;" DataSourceID="SqlDataSourceApprover"
DataTextField="APPROVNAME" DataValueField="APPROVERID"
SelectedValue='<%# Bind("approverid") %>'>
</asp:DropDownList>
</InsertItemTemplate>
....
<EditItemTemplate>
<asp:DropDownList ID="DropDownList7" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SQLLEAVECODE"
style="text-transform:uppercase;" DataTextField="LEAVETYPE"
DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
SelectedValue='<%# BIND("REQLEAVECODE") %>' ViewStateMode="Enabled"
Width="165px" Height="19px">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server" DataSourceID="SQLLEAVECODE"
DataTextField="LEAVETYPE" style="text-transform:uppercase;" DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList6_SelectedIndexChanged"
AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="166px" Height="19px"><asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="REASON"
DataValueField="REASON" Height="19px"
onselectedindexchanged="DropDownList5_SelectedIndexChanged1"
SelectedValue='<%# Bind("leavetype") %>' Visible="False" Width="163px">
</asp:DropDownList>
....
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSourceApprover" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT APPROVERID, APPROVNAME FROM BWAPPROVER ORDER BY APPROVERID">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT REASON, LEAVECODE FROM BWLEAVRSN">
<SelectParameters>
<asp:ControlParameter ControlID="Label27" Name="LEAVECODE" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SQLLEAVECODE" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT LEAVETYPE, LEAVECODE FROM BWLVTYPE ORDER BY LEAVECODE">
</asp:SqlDataSource>
直接为DropDownList5
更改您的SqlDataSource您的错误现在可能是由 SqlDataSource1 尝试从Label
内部访问DetailsView
引起的。这不可能真的发生,所以直接改变参数。
更改参数类型
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringEvent %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringEvent.ProviderName %>"
SelectCommand="SELECT REASON, LEAVECODE FROM BWLEAVRSN">
<SelectParameters>
<asp:Parameter Name="LEAVECODE" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
更改Parameter
protected void DropDownList6_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
string selectedValue = lvtype.SelectedValue.ToString().ToUpper();
if (selectedValue == "4 " || selectedValue == "1F")
{
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));
SqlDataSource1.SelectParameters["LEAVECODE"].DefaultValue = selectedValue;
lvreason.Visible = true;
}
}