C# asp.net中继器内部的下拉列表
我尝试在repeater中添加C# asp.net中继器内部的下拉列表,c#,asp.net,C#,Asp.net,我尝试在repeater中添加DropdownList,但在本例中,我替换的是grdfilaprove 代码 我更新我的问题 这是按钮代码 foreach (RepeaterItem row in Repeater2.Items) //foreach (GridViewRow row in GrdFileApprove.Rows) { if (row.**RowType** == DataControlRowType.DataRow)
DropdownList
,但在本例中,我替换的是grdfilaprove
代码
我更新我的问题
这是按钮代码
foreach (RepeaterItem row in Repeater2.Items)
//foreach (GridViewRow row in GrdFileApprove.Rows)
{
if (row.**RowType** == DataControlRowType.DataRow)
{
DropDownList DropDownListcontrol =
((DropDownList)**dataItem.**FindControl("DropDownList4"));
//DropDownList DropDownListcontrol = row.FindControl("DropDownList4")
as DropDownList;
SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@DocID", SqlDbType.Int).Value =
Convert.ToInt32((row.Cells[1].Text));
cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value =
Convert.ToInt32(DropDownListcontrol.SelectedValue);
cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value =
(Session["Login2"]);
cmd.ExecuteNonQuery();
DMSLIB.Doc myDoc = new DMSLIB.Doc();
myDoc.MarkDocAs(Convert.ToInt16(row.**Cells**[1].Text),
Convert.ToInt32(DropDownListcontrol.SelectedValue));
}
else
{
apfi.Text = "Error";
}
}
现在,当我使用这个时,会显示这个错误
1.RowType
错误“System.Web.UI.WebControls.RepeaterItem”不包含“RowType”的定义,并且找不到接受类型为“System.Web.UI.WebControls.RepeaterItem”的第一个参数的扩展方法“RowType”(是否缺少using指令或程序集引用?
2.dataItem错误当前上下文中不存在名称“dataItem”
3.CellsSystem.Web.UI.WebControls.RepeaterItem不包含“Cells”的定义,并且找不到接受“System.Web.UI.WebControls.RepeaterItem”类型的第一个参数的扩展方法“Cells”(是否缺少using指令或程序集引用?
4.细胞
“System.Web.UI.WebControls.RepeaterItem”不包含“Cells”的定义,并且找不到接受“System.Web.UI.WebControls.RepeaterItem”类型的第一个参数的扩展方法“Cells”(是否缺少using指令或程序集引用?
谢谢我已经试着了解您在寻找什么,我想您需要这个来为新的中继器循环正确的项目:
foreach(RepeaterItem dataItem in YourRepeater.Items)
{
DropDownList DropDownListcontrol= ((DropDownList)dataItem.FindControl("DropDownList4"));
// Your code
}
您需要使用Repeater的ItemDataBound。还需要检查ItemType,如下所示:
void Repeater1_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList DropDownListcontrol = e.Item.FindControl("DropDownList4") as DropDownList;
//Do other tasks
}
}
我不太明白你的问题。我想这应该是你们想要的,以前我使用gridview,但现在我使用repeater,所以当我实现repeater时,然后我要替换这个GRDFLeapProve。对不起,尽管有很多相似之处,但从gridview到repeater并不是搜索和替换。你必须了解repeater是如何工作的,并进行一些移植(这将导致你得到与上面链接的结果类似的结果)请看我的更新问题,当我实现你的代码时,它显示了一些错误。不,我已经在论坛上回答了你的问题。如果这是一个不同的想法,请忘记我的评论。
void Repeater1_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList DropDownListcontrol = e.Item.FindControl("DropDownList4") as DropDownList;
//Do other tasks
}
}