asp.net - 在 Asp.Net 中单击 GridView 中的添加按钮时,如何在下拉列表中删除先前选定的项目
问题描述
单击gridview asp.net,如何删除下拉添加按钮中的最后一行选定项目。
GridViewRow gvrow = (GridViewRow)((Control)e.CommandSource).NamingContainer;
if (e.CommandName == "Add")
{
ddt = CreateDt();
int j = 0;
foreach (GridViewRow gr in GvPatientAccomDtls.Rows)
{
ddt.Rows.Add();
ddt.Rows[j]["TreatmentCode"] = ((DropDownList)gr.FindControl("ddlTreatment")).SelectedValue;
ddt.Rows[j]["Days"] = ((TextBox)gr.FindControl("txtDays")).Text;
ddt.Rows[j]["Cost"] = ((TextBox)gr.FindControl("txtCost")).Text;
j++;
}
ddt.Rows.Add();
GvPatientAccomDtls.DataSource = ddt;
GvPatientAccomDtls.DataBind();
}
解决方案
您可以使用RowDataBound事件处理
void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
var thisRow = (DataRowView)e.Row.DataItem;
var source = thisRow.DataView;
var lastRowIndex = e.Row.DataItemIndex -1;
DataRowView lastRow = null;
var ddl = (DropDownList)e.Item.FindControl("ddl");
DropDownList ddlLast = null;
if(lastRowIndex>=0){
lastRow = source[lastRowIndex];
ddlLast = (DropDownList)((GridView)sender).Rows[lastRowIndex].FindControl("ddl");
//remove the items of this ddl according to the items of the last dll
}
}
}
推荐阅读
- java - Java - 特定线程结束后的触发动作
- python-3.x - 在具有多个逗号分隔值的元素内搜索特定数字?
- statistics - 在执行逻辑回归之前删除参考虚拟变量的原因是什么?
- ruby - ruby 2.5:在 tcp 套接字的读取上设置超时
- git - Git - 除了项目的特定子目录之外,忽略项目中其他任何地方所做的工作?
- amazon-web-services - 当 ssh 进入 EC2 时,Jenkins 无法创建目录“/var/lib/jenkins/.ssh”
- mongodb - mongodb在集合中查找不同的文档
- r - 将具有两个输入的函数应用于数据框中的数据组
- flutter - 将 LinearProgressIndicator 的方向更改为垂直
- sql-server - 可以使用中间临时表来 pd.read_sql 吗?