protected void btnSave_Click(object sender, EventArgs e)
    {
        //id, farmerid, productid, quantity, rate, createddate, isdeleted

        Int64 Result = 0, Result1 = 0;

        if (Request.QueryString["id"] != null)
        {
        }
        else
        {
            product         objproduct         = new product();
            dispatchdetails objdispatchdetails = new dispatchdetails();


            if (Session["userid"] != null)
            {
                objdispatchdetails.senderid = Convert.ToInt64(Session["userid"]);
            }
            else
            {
                Response.Redirect(Page.ResolveUrl("~/default.aspx"));
            }

            foreach (RepeaterItem item in Repeater1.Items)
            {
                //qtyrequested = int.Parse((item.FindControl("LabelQuantity") as Label).Text);

                Label pid = (Label)item.FindControl("lblproductid");
                //Label rate = (Label)item.FindControl("lblrate");
                TextBox quantity = (TextBox)item.FindControl("txtqty");

                //objfarmer.farmerid = Convert.ToInt64(hffarmerid.Value);

                objdispatchdetails.productid = Convert.ToInt64(pid.Text);
                objdispatchdetails.quantity  = Convert.ToInt64(quantity.Text);


                Result = (new Cls_dispatchdetails_b().Insert(objdispatchdetails));
            }


            if (Result > 0)
            {
                Clear();
                spnMessgae.Style.Add("color", "green");
                spnMessgae.InnerText = "Information Saved Successfully!!!";
            }
            else
            {
                Clear();
                spnMessgae.Style.Add("color", "red");
                spnMessgae.InnerText = "Failed To Save The Information...";
            }


            //Response.Redirect(Page.ResolveUrl("~/managefarmers.aspx?mode=i"));
            //}
        }
    }
        public Int64 Insert(dispatchdetails objdispatchdetails)
        {
            Int64 result = 0;

            try
            {
                //id, farmerid, productid, quantity, rate, createddate, isdeleted

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "dispatchdetails_Insert";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection  = ConnectionString;

                SqlParameter param = new SqlParameter();
                param.ParameterName = "@id";
                param.Value         = objdispatchdetails.id;
                param.SqlDbType     = SqlDbType.BigInt;
                param.Direction     = ParameterDirection.InputOutput;
                cmd.Parameters.Add(param);


                cmd.Parameters.AddWithValue("productid", objdispatchdetails.productid);
                cmd.Parameters.AddWithValue("senderid", objdispatchdetails.senderid);
                cmd.Parameters.AddWithValue("quantity", objdispatchdetails.quantity);


                ConnectionString.Open();
                cmd.ExecuteNonQuery();
                result = Convert.ToInt64(param.Value);
            }
            catch (Exception ex)
            {
                ErrHandler.writeError(ex.Message, ex.StackTrace);
                return(result);
            }
            finally
            {
                ConnectionString.Close();
            }
            return(result);
        }