- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 DetailsView 在数据库中插入行。 Row 有字段 id、subcategory_id 等。我想动态填充在 TemplateField 中使用的下拉列表 ddl_subcategories。第一个下拉列表 ddl_categories 的选定项目值用作为 ddl_subcategories 生成集合的参数。我尝试使用 UpdatePanel,但 DataBind 方法返回错误“Eval()、XPath() 和 Bind() 等数据绑定(bind)方法只能在数据绑定(bind)控件的上下文中使用。”。
有网页表单的代码
<asp:DetailsView ID="dvw" runat="server" Height="50px" Width="125px"
AutoGenerateRows="False" DataSourceID="ods"
DefaultMode="Insert" DataKeyNames="Section_id"
OnDataBound="dvw_DataBound" OnItemUpdated="dvw_ItemUpdated"
OnItemCommand="dvw_ItemCommand">
<Fields>
<asp:TemplateField HeaderText="Category" >
<ItemTemplate>
<asp:DropDownList ID="ddl_categories" runat="server" AutoPostBack="true" DataSourceID="ods_categories"
DataTextField="Name" DataValueField="Category_id" OnSelectedIndexChanged="category_select_index_changed"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subcategory" >
<ItemTemplate>
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddl_subcategories" runat="server"
SelectedValue='<%# Bind("Subcategory_id") %>' />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddl_categories" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
...
</Fields>
</asp:DetailsView>
protected void category_select_index_changed(object sender, EventArgs e)
{
DropDownList ddl_categories = (DropDownList)dvw.FindControl("ddl_categories");
List<SUBCATEGORY> sections = SUBCATEGORY.Select_all_by_parameters(Int32.Parse(ddl_categories.SelectedValue));//Select all subcategories by id of category
DropDownList ddl_subcategories= (DropDownList)dvw.FindControl("ddl_subcategories");
ddl_subcategories.DataSource = sections;
ddl_subcategories.DataTextField = "Name";
ddl_subcategories.DataValueField = "Subcategory_id";
ddl_subcategories.DataBind();
}
最佳答案
问题是当您对子类别下拉列表进行数据绑定(bind)时,没有 DataBinding 上下文(参见 here 了解更多信息,请注意 David Fowler 的评论)。我不认为 UpdatePanel 是问题,因为无论有没有它,行为都是相同的(如果您将整个 DetailsView 包装在 UpdatePanel 中)。
一种解决方案是单独加载项目,而不是对控件进行数据绑定(bind)。我承认,这似乎有点笨拙,但它确实有效。
protected void category_select_index_changed(object sender, EventArgs e)
{
DropDownList ddl_categories = (DropDownList)dvw.FindControl("ddl_categories");
IEnumerable<SUBCATEGORY> sections = new SUBCATEGORY[] { new SUBCATEGORY() { Name = "First " + ddl_categories.SelectedValue, Subcategory_id = "1" }, new SUBCATEGORY() { Name = "Second", Subcategory_id = "2" } };
DropDownList ddl_subcategories = (DropDownList)dvw.FindControl("ddl_subcategories");
ddl_subcategories.Items.Clear();
foreach (SUBCATEGORY cat in sections)
{
ddl_subcategories.Items.Add(new ListItem(cat.Name, cat.Subcategory_id));
}
}
protected void ods_OnInserting(object sender, ObjectDataSourceMethodEventArgs e)
{
DropDownList ddl_subcategories = (DropDownList)dvw.FindControl("ddl_subcategories");
e.InputParameters["Subcategory_id"] = ddl_subcategories.SelectedValue;
}
关于asp.net - 如何在DetailsView内的UpdatePanel中将数据绑定(bind)到DropDownList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3426299/
我整个下午都在尝试使用 CODE BEHIND 来完成此操作,但没有成功,所以我要求提供一些 C# 代码。 基本上,我在主/从关系中有一个 GV 和一个 DV。 GV 显示 ID 和名称。如果我在 G
我似乎无法让我的详细信息 View 进入编辑模式。我以编程方式绑定(bind)数据源。当项目命令是“编辑”时,我将模式更改为“编辑”并重新绑定(bind)数据源。我检查了控件数据绑定(bind)后,它
当用户转到指定页面时,我将 DetailsView 附加到 SqlDataSource 并且已经设置为插入模式。我实际上是将它用作某些事件的注册页面。我不想让用户输入他们的“用户名”,而是希望该字段根
我已将 DropDownList 控件添加到 DetailsView,并试图让它绑定(bind)到我的更新/插入方法的“状态”参数。 '> New York .... 我已经用 50 个状态填充
默认情况下,DetailsView 支持 2 列。我想添加第三列。使用DetailsView 可以实现这一点吗?在每个字段中创建一个表格并不能达到我想要的效果,因为第三列无法正确对齐。 我知道我可以使
我有一个处于插入模式的 DetailsView: 当然,插入/取消按钮的样式相同。 是否可以将这两个分别设置为一个蓝色和一个黄色? 在 FormView 中,您可以像这样单独定义按钮: Deta
我是 .NET 4 网络开发的新手,我正试图弄清楚它应该如何工作。在我的页面上,我有一个下拉列表、一个文本框、一个搜索按钮和一个由实体数据源连接的详细信息 View 。实体源和详细信息 View 设置
注意:我已经更新了这个问题的代码,使示例更清晰一些,并利用了下面 Karl Anderson 提供的示例代码。我也愿意接受其他方法来完成我需要完成的工作。 我正在创建一个表单,其中包含多个复选框,每个
我正在尝试从 DetailsView 控件中检索数据,以便将它们输入到另一个数据库表中。我查看了其他人提出的其他问题,但他们的问题都不适合我的情况,即试图访问 SQL 数据库。最终,我找不到我需要的答
MSDN DetailsView.EnableModelValidation 的文档非常简短: Gets or sets a value that indicates whether data-mod
我在页面上有一个 asp.net detailsview 控件。我注意到它总是显示我的数据库字段中的原始文本,它不会解释文本中的 html - 因此它显示 mytext 而不是仅以粗体显示 mytex
我想知道 DetailsView/FormView 和 ObjectDataSource 是否有足够的能力来插入/编辑您的记录? 或者更好地问你你更喜欢使用它们还是自己制作表格? 因为有时将它们用于复
我有一个带有模板字段的 DetailsView 控件,如下所示: ' runat="server"> ' oncommand="btnUpdateCommand"/>
我正在尝试将数据表绑定(bind)到详细信息 View ,但并非数据表中的所有记录都显示在详细信息 View 中。 例如,我的数据表将有 2 个不同的行。当绑定(bind)到详细信息 View 时,它
网络和 C# 4。 我有一个 DetailsView 控件,我使用一些自定义逻辑进行数据绑定(bind)。 在我的 DetailsView 中输入数据时,我想使用 Event "Inserted"(或
实际上我对 Xcode 很陌生,无法通过谷歌搜索找到以下两个问题的答案: 简而言之:我正在开发一个显示提案的 iPad 应用程序。为此,您应该从 MasterView 中的表格中选择一个建议,然后在横
如何制作特定高度的特定详情 View 行?我尝试了 css 和 itemstyle-height,但我似乎错位了我的大脑和/或明显不明白其中的某些东西是如何工作的。 可能听起来很愚蠢或不适合使用,但我
我有一个 ASP.NET GridView ,它有几个关联的详细信息 View 和一个辅助 GridView 。当用户单击 gridview 中的一行时,detailsviews 会在 gridvie
我有一个绑定(bind)到 SqlDataSource 的 DetailsView。它还有一个 Edit CommandField,显示在自动生成的行的底部。
我正在使用 ASP DetailsView并希望元素标题根据 DetailsView 的模式而有所不同在。 我有两张图片 - 每张都是 500 像素宽和 30 像素高。右边的 300px 是白色的,而
我是一名优秀的程序员,十分优秀!