asp.net中的转发器内的下拉列表

时间:2013-11-07 13:17:02

标签: c# asp.net

我尝试在转发器中添加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.Cells 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.Cells     '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?)

thankx

2 个答案:

答案 0 :(得分:0)

我试图了解您在寻找什么,我认为您需要循环使用新转发器的正确​​项目:

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

    // Your code
}

答案 1 :(得分:0)

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