【问题标题】:dropdown inside the repeater in asp.netasp.net中中继器内的下拉菜单
【发布时间】:2013-11-07 13:17:01
【问题描述】:

我尝试在转发器中添加DropdownList,但我在此替换而不是grdfilapprove

代码

 foreach (GridViewRow row in **GrdFileApprove**.Rows)
        {

            if (row.RowType == DataControlRowType.DataRow)
            {
                DropDownList DropDownListcontrol =
               row.FindControl("DropDownList4")       as  
             DropDownList;  

                SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
                cmd.CommandType = CommandType.StoredProcedure;

我更新了我的问题 这是按钮代码

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 error 'System.Web.UI.WebControls.RepeaterItem' does not contain a definition for 'RowType' and no extension method 'RowType' accepting a first argument of type'System.Web.UI.WebControls.RepeaterItem' could be found (are you missing a using directive or an assembly reference?)

2.dataItem error the name 'dataItem' does not exist in the current context

3.细胞System.Web.UI.WebControls.RepeaterItem does not contain a definition for 'Cells' and no extension method 'Cells' accepting a first argument of type 'System.Web.UI.WebControls.RepeaterItem' could be found (are you missing a using directive or an assembly reference?)

4.细胞 'System.Web.UI.WebControls.RepeaterItem' does not contain a definition for 'Cells' and no extension method 'Cells' accepting a first argument of type 'System.Web.UI.WebControls.RepeaterItem' could be found (are you missing a using directive or an assembly reference?)

谢谢

【问题讨论】:

  • 不确定我是否理解您的问题。我想这应该是你要找的stackoverflow.com/q/1432790/1236044
  • 以前我使用gridview,但现在我使用repeater,所以当我实现repeater时,我替换这个grdfileapprove..
  • 抱歉,尽管有很多相似之处,但从 GridView 迁移到 Repeater 并不是搜索和替换。您必须了解中继器的工作原理并进行一些移植(这应该会导致您获得类似于上面链接的结果)

标签: c# asp.net


【解决方案1】:

我已尝试了解您在寻找什么,我认为您需要这个循环为新中继器循环输入正确的项目:

foreach(RepeaterItem dataItem in YourRepeater.Items)        
{ 
    DropDownList DropDownListcontrol= ((DropDownList)dataItem.FindControl("DropDownList4"));

    // Your code
}

【讨论】:

  • 请在我实现你的代码时查看我的更新问题,它显示了一些错误
  • 没有,你在论坛问我就回复了。如果有不同的想法,请忘记我的评论。
【解决方案2】:

你需要使用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
    }
}    

【讨论】:

    猜你喜欢
    • 2018-01-27
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    相关资源
    最近更新 更多