I try to add DropdownList
in repeater but what I replace instead of grdfilapprove
in this
code
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;
I update my question this is button code
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";
}
}
now when i use this this show me error in this
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
I have tried to understand what you are looking for and I think you need this to loop in the correct item for the new repeater:
foreach(RepeaterItem dataItem in YourRepeater.Items)
{
DropDownList DropDownListcontrol= ((DropDownList)dataItem.FindControl("DropDownList4"));
// Your code
}
You need to use Repeater's ItemDataBound. Also need to check the ItemType, like below:
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.