gpt4 book ai didi

c# - ASP Gridview 下拉列表选择已更改,如何填充 rowDataBound() 以外的下拉列表

转载 作者:行者123 更新时间:2023-11-30 22:17:26 25 4
gpt4 key购买 nike

我在 ASP 中有一个 gridview,具有包含 selecteditdelete 的 template Fields 链接每一行,页脚包含 insert 链接。

每行有两个dropdownlists,比方说:Categorysub-category,当我改变的内容时category DropDownList sub-category DropDownList 应该自动显示相应的内容。

我已经尝试编写一个 onSelectedIndexChanged 处理程序,但我不知道如何继续。 有什么想法吗? (请记住,我使用了所有 rowDataBound() 代码来填充下拉列表)

换句话说,如何填充 row_databound() 以外的下拉列表

代码:

protected void grdBulkScheduler_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlCategory = (DropDownList)e.Row.FindControl("ddlCategory");
if (ddlCategory != null)
{
ddlCategory .DataSource = cData.GetCategory();
ddlCategory .DataValueField = "c_ID";
ddlCategory .DataTextField = "c_Text";
ddlCategory .DataBind();
}

在这里,我从 GridViewRowEventArgs

中找到下拉列表 category

在 selectedIndexChanged 处理程序中,如何找到 DropDownList? 因为 DropDownList ddlCategory = (DropDownList)e.Row.FindControl("ddlCategory") 不工作

最佳答案

听起来您想使用您在类别下拉列表中选择的值将数据绑定(bind)到子类别下拉列表。你可以这样做:

protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = (GridViewRow)((DropDownList)sender).Parent.Parent;
DropDownList ddlSubCategory = (DropDownList)row.FindControl("ddlSubCategory");
ddlSubCategory.DataSource = //whatever you want to bind, e.g. based on the selected value, using((DropDownList)sender).SelectedValue;
ddlSubCategory.DataBind();
}

如果我误解了你,请在评论中纠正我。

关于c# - ASP Gridview 下拉列表选择已更改,如何填充 rowDataBound() 以外的下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16737372/

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