kapil dev

kapil dev

  • NA
  • 8
  • 1.5k

Please tell me whole functionality for Editing repeater.................Thanks

Oct 18 2012 4:33 AM
 private void BindRepeater()
    {
        SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand SqlCmd = new SqlCommand("select * from SchoolGenDetails", SqlCnn);
        SqlDataAdapter SqlAd1 = new SqlDataAdapter(SqlCmd);
        DataSet ds = new DataSet();
        SqlAd1.Fill(ds);
        cpRepeater.DataSource = ds;
        cpRepeater.DataBind();
    }

    //The code in ItemDataBound event of repeater.

    //Populating the dropdownlist dynamically.

    
   
    protected void cpRepeater_ItemCommand1(object source, RepeaterCommandEventArgs e)
    {
        //DropDownList ddlType = (DropDownList)e.Item.FindControl("ddlType");
        //if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        //{
        //    SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //    SqlCommand SqlCmd = new SqlCommand("select * from Country", SqlCnn);
        //    SqlDataAdapter SqlAd1 = new SqlDataAdapter(SqlCmd);
        //    DataSet ds = new DataSet();
        //    DataTable dt = new DataTable();
        //    SqlAd1.Fill(dt);
        //    ddlType.DataTextField = "CountryName";
        //    ddlType.DataValueField = "CountryID";
        //    ddlType.DataSource = dt;
        //    ddlType.DataBind();
           
        //}
        TextBox txtname = (TextBox)e.Item.FindControl("txtName");
        txtname.Visible = true;

        Label lblName = (Label)e.Item.FindControl("lblName");
        lblName.Visible = false;
        LinkButton lnkUpdate = (LinkButton)e.Item.FindControl("lnkUpdate");
        lnkUpdate.Visible = true;
        LinkButton lnkCancel = (LinkButton)e.Item.FindControl("lnkCancel");
        lnkCancel.Visible = true;
        LinkButton lnkEdit = (LinkButton)e.Item.FindControl("lnkEdit");
        lnkEdit.Visible = false;
        if (e.CommandName == "update")
        { }
        else if (e.CommandName == "cancel")
        {   
            BindRepeater();
        }


    }
    protected void cpRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DropDownList ddlType = (DropDownList)e.Item.FindControl("ddlType");
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            SqlCommand SqlCmd = new SqlCommand("select * from Country", SqlCnn);
            SqlDataAdapter SqlAd1 = new SqlDataAdapter(SqlCmd);
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlAd1.Fill(dt);
            ddlType.DataTextField = "CountryName";
            ddlType.DataValueField = "CountryID";
            ddlType.DataSource = dt;
            ddlType.DataBind();

        }
      
      
        ////TextBox txtname = (TextBox)e.Item.FindControl("txtName");
        ////txtname.Visible = true;

        ////Label lblName = (Label)e.Item.FindControl("lblName");
        ////lblName.Visible = false;
    }















this is my code......

I m hiding the Link button  on item command is this right appproach...........

Attachment: repeaterediting.rar

Answers (1)