gpt4 book ai didi

c# - 错误 - 数据绑定(bind)方法,例如 Eval()、XPath() 和 Bind()

转载 作者:太空狗 更新时间:2023-10-30 01:23:10 25 4
gpt4 key购买 nike

在具有两个数据绑定(bind)下拉列表的详细信息 View 上按下提交按钮后,我一直收到此错误。我不在代码中的任何地方使用 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以及搜索了很多论坛。请帮忙。

我正在尝试使用下拉列表让用户选择值来填充数据库。我表单中的每个字段都是一个模板并且是数据绑定(bind)的。

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="&quot;Y/N&quot;" DataValueField="&quot;Y/N&quot;" 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 &quot;Other&quot; 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" />
&nbsp; &nbsp;
<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="New" Height="21px" Text="New" Width="65px" />
&nbsp; &nbsp;
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
&nbsp;
<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" />
&nbsp;
<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>

最佳答案

我注意到的一件事是第一个 丢失了,我怀疑它只是从复制和粘贴中丢失了。我不认为它会编译,所以我猜你的代码中不存在。但是,值得检查。

您的错误可能是由于 TemplateField 中有 SqlDataSource 引起的。将它们移到 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 试图从 DetailsView 内部访问 Label 引起的。这不可能真的发生,所以直接改变参数。

改变你的参数类型

<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>

改变参数

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;
}
}

关于c# - 错误 - 数据绑定(bind)方法,例如 Eval()、XPath() 和 Bind(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11971556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com